AcWing 462. 扫雷游戏
原题链接
简单
作者:
贩卖日落_02
,
2025-04-02 23:39:31
· 河南
,
所有人可见
,
阅读 1
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
int n, m;
char a[N][N];
inline bool inb(int x, int y) {
return x > 0 && y > 0 && x <= n && y <= m;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i]+1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == '*') { cout << '*'; continue; }
int cnt = 0;
for (int k = 0; k < 8; k++) {
int nx = i + dx[k], ny = j + dy[k];
if (inb(nx, ny) && a[nx][ny] == '*') cnt++;
} cout << cnt;
}
cout <<endl;
}
return 0;
}