AcWing 462. 扫雷游戏
原题链接
简单
作者:
cht
,
2020-07-15 20:27:39
,
所有人可见
,
阅读 466
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m;
char g[N][N];
int d[N][N];//有雷:-1
int main()
{
scanf("%d%d", &n, &m);
memset(d, 0, sizeof d);
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
{
cin >> g[i][j];
if(g[i][j] == '*') d[i][j] = -1;
}
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
{
pair<int, int> t = {i, j};
for(int x = t.first - 1; x <= t.first + 1; x ++)
for(int y = t.second - 1; y <= t.second + 1; y ++)
{
if(x < 0 || x >= n || y < 0 || y >= n) continue;
if(x == t.first && y == t.second) continue;
if(d[i][j] != -1) continue;
if(d[x][y] == -1) continue;
d[x][y] += 1;
}
}
for(int i = 0; i < n; i ++, cout << endl)
for(int j = 0; j < m; j ++)
{
if(d[i][j] == -1) printf("*");
else cout << d[i][j];
}
return 0;
}