int output(int x, int y, int z, int k, char ch[][k]) {
int count = 0;
//在当前值周围进行循环判断
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
//若有*且不超出矩阵范围,地雷加1
if (ch[i][j] == '*' && i >= 0 && i < z && j >= 0 && j < k)
count++;
}
}
return count; //返回地雷数
}
int main() {
int n, m, count = 0;
scanf("%d %d\n", &n, &m);
char ch[n][m];
//依次输入字符
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%c ", &ch[i][j]);
}
}
//依次判断并输出字符
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (ch[i][j] != '*') { //字符不为*时,计算当前值应为多少
ch[i][j] = output(i, j, n, m, ch); //字符替换地雷数值
printf("%d", ch[i][j]); //输出当前值
} else printf("%c", ch[i][j]); //字符为*时,直接输出
}
printf("\n");
}
return 0;
}