連續1的個數演算法----java版1.0

abcbbc發表於2007-05-17
根據C版翻譯成java版[@more@]

package cn.withe;

public class Count {
public static int staticpoint=0;
public static int points[]=new int[11];
public final static int MAXCOL=10;
public final static int MAXROW=10;

public static int[][] number={

{1,1,1,1,1,0,0,0,0,0},
{1,1,1,0,0,0,1,1,1,1},
{0,0,1,1,0,0,0,0,0,0},
{1,1,0,1,1,0,1,1,0,1},
{0,1,0,1,0,1,1,0,0,1},
{1,1,1,1,0,0,0,0,0,0},
{0,0,0,0,0,1,1,1,1,1},
{1,1,1,1,1,0,0,0,0,0},
{1,1,0,0,0,0,1,1,1,1},
{1,1,1,1,0,0,0,0,1,1}
};

public static void check(int row,int col)
{
if(number[row][col]==0) return;
else
{
points[staticpoint]++;
number[row][col]=0;
if(row>0) check(row-1,col);
if(row if(col>0) check(row,col-1);
if(col }
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

for(int i=0;i for(int j=0;j {
if(number[i][j]==1)
{
staticpoint++;
points[staticpoint]=0;
check(i,j);
}

}
for(int i=1;i<=10;i++)
{
System.out.println("NO"+i+":"+points[i]);
}
}

}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/219138/viewspace-915319/,如需轉載,請註明出處,否則將追究法律責任。

相關文章