首页 > 应用开发 > IT综合 > 连续1的个数算法----java版1.0
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
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0;i
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博客 ” ,链接:https://blog.itpub.net/219138/viewspace-915319/ ,如需转载,请注明出处,否则将追究法律责任。