求高手用C++编写一个扫雷,完成大学的任务。谢谢啦

编好了发我,完全复制的网上的就算了,老师要我们有改动。
2024-12-28 03:07:51
推荐回答(1个)
回答1:

我今天刚写了一个简易版的,最核心部分,你看看行不行
#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 *(p+m*j+n)+=(*(p+(m+u)*j+n+q)==1 ? 1:0);
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 for(j=0;j fscanf(fp,"%d",&k[i][j]);
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 if(k[m][n]==1) printf("*");
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