提交时间:2024-09-20 17:02:11

运行 ID: 51293

#include<bits/stdc++.h> using namespace std; char d[110][110]; int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) cin>>d[i][j]; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(d[i][j]=='*') cout<<'*'; else{ int count=0; if(d[i-1][j]=='*') count++; if(d[i+1][j]=='*') count++; if(d[i][j-1]=='*') count++; if(d[i][j+1]=='*') count++; if(d[i-1][j-1]=='*') count++; if(d[i+1][j-1]=='*') count++; if(d[i-1][j+1]=='*') count++; if(d[i+1][j+1]=='*') count++; cout<<count; } } cout<<endl; } return 0; }