May
unread,Jul 1, 2011, 3:16:56 PM7/1/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ACM-CPC-MUST
/*
Question ID: 10189 (Minesweeper)
Tool: DevC++ 7.3.1.3
Rank: 5463
Time: 0.012s
*/
#include <iostream>
using namespace std;
int n,m,i,j;
bool IsExist(int y,int x){
return (y>=0&&x>=0&&y<n&&x<m);
}
int main(){
int count=1;
cin >> n >> m;
while(n!=0&&m!=0){
int out[n][m];
char in[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin >> in[i][j];
out[i][j]=0;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(in[i][j]!='*') continue;
if(IsExist(i-1,j-1)) out[i-1][j-1]++;
if(IsExist(i,j-1)) out[i][j-1]++;
if(IsExist(i+1,j-1)) out[i+1][j-1]++;
if(IsExist(i-1,j)) out[i-1][j]++;
if(IsExist(i+1,j)) out[i+1][j]++;
if(IsExist(i-1,j+1)) out[i-1][j+1]++;
if(IsExist(i,j+1)) out[i][j+1]++;
if(IsExist(i+1,j+1)) out[i+1][j+1]++;
}
}
cout << "Field #" << count++ << ":\n";
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(in[i][j]=='*') cout << "*";
else cout << out[i][j];
}
cout << endl;
}
cin >> n >> m;
if(n!=0&&m!=0) cout << endl;
}
return 0;
}