-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10189.c
65 lines (61 loc) · 994 Bytes
/
10189.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,a[500][500],i,j,count=0,c,index=1,mines=0;
while(scanf("%d%d",&n,&m)&&n&&m)
{
getchar();
if(count>0)
printf("\n");
memset(a,0,sizeof(a));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%c",&c);
if(c=='*')
a[i][j]=-1;
else
a[i][j]=0;
}
getchar();
}
for(i=0;i<n;i++)
for(j=0;j<m;j++){
if(a[i][j]==0)
{
mines=0;
if(i-1>=0&&a[i-1][j]==-1)
mines++;
if(j-1>=0&&a[i][j-1]==-1)
mines++;
if(i+1<n&&a[i+1][j]==-1)
mines++;
if(j+1<m&&a[i][j+1]==-1)
mines++;
if(i-1>=0&&j-1>=0&&a[i-1][j-1]==-1)
mines++;
if(i-1>=0&&j+1<m&&a[i-1][j+1]==-1)
mines++;
if(i+1<n&&j-1>=0&&a[i+1][j-1]==-1)
mines++;
if(i+1<n&&j+1<m&&a[i+1][j+1]==-1)
mines++;
a[i][j]=mines;
}
}
printf("Field #%d:\n",index);
index++;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]==-1)
printf("*");
else
printf("%d",a[i][j]);
if(j==m-1)
printf("\n");
}
}
count++;
}
return 0;
}