问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
int main()
{
int m, n;
char a[100][100];
int count[100][100];
scanf("%d%d", &m, &n);
setbuf(stdin, NULL);
/*fflush(stdin);*/
for (int i =1; i <=m; i++)
{
for (int j = 1; j <= n; j++)
{
scanf("%c", &a[i][j]);
}
setbuf(stdin, NULL);
/*fflush(stdin);*/
}
for (int i =1; i <= m; i++)
{
for (int j =1; j <= n; j++)
{
if (i > 0) {
if (a[i - 1][j] == '*')
count[i][j]++;
if (a[i - 1][j - 1] == '*')
count[i][j]++;
if (a[i - 1][j + 1] == '*')
count[i][j]++;
if (a[i][j - 1] == '*')
count[i][j]++;
if (a[i][j + 1] == '*')
count[i][j]++;
if (a[i + 1][j] == '*')
count[i][j]++;
if (a[i + 1][j - 1] == '*')
count[i][j]++;
if (a[i + 1][j + 1] == '*')
count[i][j]++;
}
}
}
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (a[i][j] == '?')
a[i][j] = '0' + count[i][j];
}
}
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
printf("%c", a[i][j]);
}
printf("\n");
}
return 0;
}
```#include<stdio.h>
//#include<stdlib.h>
int a[105][105]={0};//一张地图,有雷为一,无雷为零
int main()
{
//memset(a, 0, sizeof(a));//地图最开始清空
//int b[105][105];//一张地图,有雷为一,无雷为零
int n, m;
char tmp[105][105];
scanf("%d%d", &m, &n);
/*setbuf(stdin, NULL);*/
for (int i = 1; i <=m; i++)//读入地图
{
for (int j = 1; j <=n; j++)
{
scanf("%c",&tmp[i][j]);
if (tmp[i][j] == '*')
a[i][j] = 1;//如果是地雷就将这个点设为一
}
}
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (a[i][j] == 1) printf("*"); //如果是地雷不用输出数字
else
{
printf("%d", a[i + 1][j + 1] + a[i + 1][j - 1] + a[i + 1][j] + a[i][j + 1] + a[i][j - 1] + a[i - 1][j + 1] + a[i - 1][j] + a[i - 1][j - 1]);
//将旁边的雷加起来输出 (旁边的雷直接变成1)
}
}
printf("\n");
}
return 0;//愉快的结束了主程序
}
我换了一种解法还是过不了
```c
运行结果及报错内容
但是我自己输入时都对啊