解题思路:
注意事项:
参考代码
#include
using namespace std;
int main()
{
int x,y,num=0;
while(cin>>x>>y){
if(x==0&&y==0)break;
num++;
char m[x+2][y+2];
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
cin>>m[i][j];
}
}
int s[x+2][y+2]={0};//1到x为有效的;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
if(m[i][j]=='*'){
s[i][j]=-100;
s[i+1][j]++;
s[i+1][j+1]++;
s[i+1][j-1]++;
s[i-1][j+1]++;
s[i-1][j]++;
s[i-1][j-1]++;
s[i][j+1]++;
s[i][j-1]++;
}
}
}
cout<<"Field #"<<num<<":"<<endl;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
if(s[i][j]>=0)cout<<s[i][j];
else
cout<<"*";
}
cout<<endl;
}
cout<<endl;}
return 0;
}
0.0分
2 人评分