题解 P2670 【扫雷游戏】
include <bits/stdc++.h>
using namespace std;
char a[10005][10005]; int t[10005][10005];
int main() { int n , m; cin >> n >> m; for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) { cin >> a[i][j]; t[i][j] = 0; }
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (a[i][j] == '*')//如果是雷就执行以下操作:
{
//在周围的格子中增加
t[i + 1][j]++;
t[i - 1][j]++;
t[i][j + 1]++;
t[i][j - 1]++;
t[i + 1][j + 1]++;
t[i + 1][j - 1]++;
t[i - 1][j - 1]++;
t[i - 1][j + 1]++;
}
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
if (a[i][j] == '*') cout << "*";
else cout << t[i][j];
}
cout << endl;
}
return 0;
}