首页 > 应用开发 > IT综合 > 连续1的个数算法----C版
#include
#include
#define MAXCOL 10
#define MAXROW 10
int staticpoint=0;
int count[MAXROW*MAXCOL];
struct point
{
int x;
int y;
}point[MAXCOL*MAXROW][MAXCOL*MAXROW];
int number[MAXROW][MAXCOL]=
{
0,1,0,1,0,1,0,0,0,1,
0,1,1,1,0,1,0,1,0,0,
1,1,0,1,0,1,1,0,0,0,
0,0,1,0,1,0,1,0,1,0,
1,1,0,1,1,0,0,0,1,0,
1,0,0,0,1,0,0,0,0,0,
1,1,0,0,0,1,0,1,0,0,
1,1,1,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,1,0,1
};
void check(int row,int col)
{
if(number[row][col]==0)
return;
else
{
point[staticpoint][count[staticpoint]].x=row;
point[staticpoint][count[staticpoint]].y=col;
count[staticpoint]+=1;
number[row][col]=0;
if(col<=MAXCOL-2)
check(row,col+1);
if(col>=1)
check(row,col-1);
if(row>=1)
check(row-1,col);
if(row<=MAXROW-2)
check(row+1,col);
}
}
void main()
{
for(int i=0;i
for(int j=0;j
if(number[i][j]==1)
{
staticpoint+=1;
count[staticpoint]=0;
check(i,j);
}
}
}
for(i=1;i<=staticpoint;i++)
{
cout<<"No."< for(int j=0;j
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/219138/viewspace-915318/ ,如需转载,请注明出处,否则将追究法律责任。