题解
2024-08-29 11:15:23
发布于:广东
6阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
char a[N][N];
int b[N][N];
int x[] = {-1,-1,-1,0,0,1,1,1};
int y[] = {-1,0,1,-1,1,-1,0,1};
int main(){
int n , m;
cin >> n >> m;
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
cin >> a[i][j];
if (a[i][j] == '*'){
for (int k = 0 ; k <= 7 ; k++) b[i + x[k]][j + y[k]]++;
}
}
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (a[i][j] == '*') cout << '*';
else cout << b[i][j];
}
cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个