You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 110;
|
|
|
|
|
// 依次枚举每个空格,然后统计八个方向上的相邻格子有没有地雷即可
|
|
|
|
|
int n, m;
|
|
|
|
|
char g[N][N];
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
for (int i = 0; i < n; i++) cin >> g[i];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
for (int j = 0; j < m; j++)
|
|
|
|
|
if (g[i][j] == '*')
|
|
|
|
|
cout << '*';
|
|
|
|
|
else {
|
|
|
|
|
int s = 0;
|
|
|
|
|
// 8个方向一般玩的是9宫格,然后放弃自己
|
|
|
|
|
for (int x = i - 1; x <= i + 1; x++)
|
|
|
|
|
for (int y = j - 1; y <= j + 1; y++)
|
|
|
|
|
if (x != i || y != j) {
|
|
|
|
|
if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') s++;
|
|
|
|
|
}
|
|
|
|
|
cout << s;
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|