30分求助
查看原帖
30分求助
757049
bj12z_gengruilin楼主2023/2/7 15:02
#include<bits/stdc++.h>
using namespace std;
char amp[105][105];
int mapp[105][105];
int n,m;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>amp[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			mapp[i][j]=amp[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(mapp[i][j]=='*'){
				mapp[i][j]=-1;
				continue;
			}
			mapp[i][j]=0;
			if(mapp[i+1][j]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i][j+1]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i][j-1]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i-1][j]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i+1][j+1]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i+1][j-1]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i-1][j+1]==-1){
				mapp[i][j]+=1;
			}
			if(mapp[i-1][j-1]==-1){
				mapp[i][j]+=1;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(mapp[i][j]==-1){
				cout<<'*';
				continue;
			}
			cout<<mapp[i][j];
		}
		cout<<endl;
	}
	return 0;
}
2023/2/7 15:02
加载中...