题目传送门
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char a[N][N];
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1}; //上下左右,左上,右上,左下,右下
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int n, m;
int main() {
cin >> n >> m;
//计入地雷地图
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == '*') printf("%c", '*');
else {
int cnt = 0;
for (int k = 0; k < 8; k++)
//当前点周边的*的个数是多少个?
if (a[i + dx[k]][j + dy[k]] == '*') cnt++;
printf("%d", cnt);
}
}
printf("\n");
}
return 0;
}