题解
2024-07-17 15:22:44
发布于:广东
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
string a[n];
vector<vector<int>> b(n,vector<int>(m,0));
for (int i=0;i<n;i++)cin >> a[i];
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
if (a[i][j] != '*'){
if (i > 0 && a[i-1][j] == '*')b[i][j]++;
if (j > 0 && a[i][j-1] == '*')b[i][j]++;
if (i < n-1 && a[i+1][j] == '*')b[i][j]++;
if (j < m-1 && a[i][j+1] == '*')b[i][j]++;
if (i > 0 && j > 0 && a[i-1][j-1] == '*')b[i][j]++;
if (j > 0 && i < n-1 && a[i+1][j-1] == '*')b[i][j]++;
if (i < n-1 && j < m-1 && a[i+1][j+1] == '*')b[i][j]++;
if (j < m-1 && i > 0&& a[i-1][j+1] == '*')b[i][j]++;}
}
}for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
if (a[i][j] != '*'){
cout << b[i][j];
}else cout << '*';
}cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个