-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10189.cpp
More file actions
57 lines (56 loc) · 1.45 KB
/
10189.cpp
File metadata and controls
57 lines (56 loc) · 1.45 KB
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
#include <bits/stdc++.h>
using namespace std;
struct dir
{
int x,y;
};
dir mv[] = {{1,0},{1,1},{1,-1},{-1,0},{-1,1},{-1,-1},{0,1},{0,-1}};
int main()
{
//freopen("in.txt", "rt", stdin);
//freopen("out.txt", "w+t", stdout);
int mines[100][100],n,m,kase(0);
char field[101][101];
while(scanf("%d%d",&n,&m)&&n&&m)
{
if(kase)
cout<<endl;
char l[5];
fgets(l,5,stdin);
for(int i=0; i<n; i++)
{
fgets(field[i],m+1,stdin);
fgets(l,5,stdin);
}
memset(mines,0,sizeof(mines));
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(field[i][j] == '*')
{
for(int k=0; k<8; k++)
{
if(i+mv[k].x <0 || i +mv[k].x >=n || j+ mv[k].y<0 || j+ mv[k].y >= m)
{
continue;
}
mines[i+mv[k].x][j+mv[k].y]++;
}
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(field[i][j]!='*')
field[i][j] = '0' + mines[i][j] ;
}
}
cout<<"Field #"<<++kase<<":"<<endl;
for(int i=0;i<n;i++)
cout<<field[i]<<endl;
}
return 0;
}