Why didn't it output
2024-08-14 20:52:42
发布于:浙江
15阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,m,dsbx[8] = {1,1,1,0,0,-1,-1,-1},dsby[8] = {1,0,-1,1,-1,-1,0,1};
char ch[101][101];
for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++) cin >> ch[i][j];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(ch[i][j] == '*') cout << "*";
else if(ch[i][j] == '?')
{
int cnt = 0;
for(int _ = 0; _ < 8; _++)
{
int x = dsbx[_] + i,y = j + dsby[_];
if(x >= 1 && x <= n && y >= 1 && y <= m)
{
cnt++;
}
}
cout << cnt;
}
else continue;
}
cout << endl;
}
}
这里空空如也
有帮助,赞一个