纯模拟题解
2025-07-21 19:48:47
发布于:广东
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int mine[100][100];
int main(){
int n,m;
cin >> n >> m;
char dp[n][m];
// for(int i = 0;i<100;i++){
// for(int j = 0;j<100;j++){
// cout<<mine[i][j];
// }
// cout<<endl;
// }
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin >> dp[i][j];
//cout<<dp[i][j]<<endl;
if(dp[i][j]=='*'){
mine[i][j]=-1;
for(int k=-1;k<2;k++){
//cout<<1;
for(int l = -1;l<2;l++){
if(i+k>=0&&i+k<n&&j+l>=0&&j+l<m){
if(mine[i+k][j+l]!=-1)mine[i+k][j+l] ++;
}
}
}
}
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
if(mine[i][j]== -1)cout<<'*';
else cout<<mine[i][j];
}
cout<<endl;
}
}
这里空空如也
有帮助,赞一个