ITPub博客

首页 > 应用开发 > IT综合 > 连续1的个数算法----C版

连续1的个数算法----C版

原创 IT综合 作者:abcbbc 时间:2007-05-17 10:39:26 0 删除 编辑
微软的笔试题目
答案是studenthe提供的[@more@]

#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 cout<<'('< cout< }

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/219138/viewspace-915318/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle中的大字段
请登录后发表评论 登录
全部评论

注册时间:2011-09-07

  • 博文量
    56
  • 访问量
    699643