This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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;