我今天刚写了一个简易版的,最核心部分,你看看行不行
#include
void trying(int i, int j, int *p, int m, int n)
{
int u,q;
if(*(p+m*j+n)==0&&m=0&&n>=0)
{
*(p+m*j+n)=10;
for(u=-1;u<=1;u++)
for(q=-1;q<=1;q++)
if(m+u>=0&&m+u=0&&n+q
trying(i,j,p,m+1,n);
trying(i,j,p,m-1,n);
trying(i,j,p,m,n+1);
trying(i,j,p,m,n-1);
}
}
int main()
{
int i,j,m,n;
FILE *fp=fopen("aaa.txt","r+");
fscanf(fp,"%d %d",&m,&n);
int k[m][n];
for(i=0;i
printf("Please type (x,y)\n");
scanf("%d%d",&m,&n);
trying(i,j,&k[0][0],m,n);
for(m=0;m {
for(n=0;n
else if(k[m][n]==0) printf("0");
else if(k[m][n]%10) printf("%d",k[m][n]%10);
else printf(" ");
printf("\n");
}
fclose(fp);
}
数据
10 10
1 1 1 1 1 1 1 1 1 0
1 0 1 0 0 0 0 0 0 1
0 0 0 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 0 0 0 0 1
1 1 0 1 1 0 0 0 0 1
1 1 0 0 1 1 1 1 0 0
1 1 1 0 1 1 1 1 1 1
1 1 0 0 0 0 1 1 0 1
1 1 1 1 1 0 0 0 0 1