UVa 10189 Minesweeper
1
#include <stdio.h>
2 #include
<stdlib.h>
3 #include
<iostream>
4 #include
<algorithm>
5 #include
<string.h>
6 using
namespace std;
7 int arr[105][105];
8 int ans[105][105];
9 int n,m;
10 void compute()
11 {
12 for(int i=0; i<n; i++)
13 {
14 for(int j=0; j<m; j++)
15 {
16 if(arr[i][j]==2 && ans[i][j]==-1)
17 {
18
19
if(i>0 && j>0 && arr[i-1][j-1]!=2) ans[i-1][j-1]+=1;
20
if(i>0 && arr[i-1][j]!=2) ans[i-1][j]+=1;
21
if(j>0 && arr[i][j-1]!=2) ans[i][j-1]+=1;
22
if(i>0 && arr[i-1][j+1]!=2) ans[i-1][j+1]+=1;
23
if(j>0 && arr[i+1][j-1]!=2) ans[i+1][j-1]+=1;
24
if(arr[i+1][j]!=2) ans[i+1][j]+=1;
25
if(arr[i][j+1]!=2) ans[i][j+1]+=1;
26
if(arr[i+1][j+1]!=2) ans[i+1][j+1]+=1;
27
28
29
30 }
31 }
32 }
33 }
34
35 int main()
36 {
37
38
39 int cas=1;
40 while(cin>>n>>m &&n!=0 ||m!=0)
41 {
42 string str[105];
43 if(cas!=1) cout<<endl;
44 memset(arr,0,sizeof(arr));
45 memset(ans,0,sizeof(ans));
46
47 for(int i=0; i<n; i++)
48 {
49 cin>>str[i];
50 for(int j=0; j<m; j++)
51 {
52
if(str[i][j]=='.') arr[i][j]=1;
53
else if(str[i][j]=='*') arr[i][j]=2,ans[i][j]=-1;
54 }
55 }
56 compute();
57 printf("Field
#%d:\n",cas++);
58 for(int i=0; i<n; i++)
59 {
60 for(int j=0; j<m; j++)
61 {
62
if(ans[i][j]==-1) cout<<'*';
63
else cout<<ans[i][j];
64 }
65 cout<<endl;
66 }
67 }
68 return 0;
69 }
留言
張貼留言