AcWing 462. 扫雷游戏
原题链接
简单
作者:
JACK_2
,
2024-12-31 15:33:32
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
const int N = 110;
int n, m;
char st[N][N];
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int check(int x, int y)
{
int sum = 0;
for(int i = 0; i < 8; ++i)
{
int a = x + dx[i], b = y + dy[i];
if(a < 0 || a >= n || b < 0 || b >= m) continue;
if(st[a][b] == '*') sum ++;
}
return sum;
}
int main()
{
cin >> n >> m;
for(int i = 0; i < n; ++ i)
for(int j = 0; j < m; ++j)
{
cin >> st[i][j];
}
for(int i= 0 ; i <n; ++i)
{ for(int j = 0; j < m; ++j)
{
if(st[i][j] == '*') cout << st[i][j];
else cout << check(i,j);
}
puts("");
}
}