- 扫雷游戏
- 2015-11-13 12:35:57 @
#include <iostream>
using namespace std;
char a[101][101];
char x[101][101];
int msum(int x,int y)
{ char count='0';
if(a[x+1][y]=='*') count+=1;
if(a[x-1][y]=='*') count+=1;
if(a[x][y+1]=='*') count+=1;
if(a[x][y-1]=='*') count+=1;
if(a[x+1][y+1]=='*') count+=1;
if(a[x+1][y-1]=='*') count+=1;
if(a[x-1][y+1]=='*') count+=1;
if(a[x-1][y-1]=='*') count+=1;
return count;
}
int main()
{int b,c,d,e,f,g;
cin>>b>>c;
for(int i=1;i<=b;i++)
for(int j=1;j<=c;j++)
cin>>a[i][j];
for(int i=1;i<=b;i++)
for(int j=1;j<=c;j++)
{if(a[i][j]=='*') x[i][j]='*';
if(a[i][j]=='?') x[i][j]=msum(i,j);
}
for(int i=1;i<=b;i++)
{for(int j=1;j<=c;j++)
cout<<x[i][j];
cout<<endl;
}
}