-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoj2612.cpp
More file actions
60 lines (51 loc) · 1.4 KB
/
poj2612.cpp
File metadata and controls
60 lines (51 loc) · 1.4 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
58
59
60
#include <cstdio>
#include <cstring>
#define MAXN 11
int table[MAXN][MAXN];
bool ismine[MAXN][MAXN];
int n;
bool valid(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < n;
}
void add_bomb(int x, int y) {
ismine[x][y] = true;
if(valid(x+1, y)) table[x+1][y]++;
if(valid(x-1, y)) table[x-1][y]++;
if(valid(x, y+1)) table[x][y+1]++;
if(valid(x, y-1)) table[x][y-1]++;
if(valid(x+1, y+1)) table[x+1][y+1]++;
if(valid(x-1, y+1)) table[x-1][y+1]++;
if(valid(x+1, y-1)) table[x+1][y-1]++;
if(valid(x-1, y-1)) table[x-1][y-1]++;
}
int main() {
// freopen("input.txt", "r", stdin);
while(scanf("%d\n", &n) != EOF) {
memset(table, 0, sizeof(table));
memset(ismine, false, sizeof(ismine));
char c;
for(int y = 0; y < n; ++y){
for(int x = 0; x < n; ++x) {
scanf("%c", &c);
if(c == '*')
add_bomb(x, y);
}
scanf("\n");
}
for(int y = 0; y < n; ++y){
for(int x = 0; x < n; ++x) {
scanf("%c", &c);
if(c == 'x')
if(ismine[x][y])
printf("*");
else
printf("%d", table[x][y]);
else
printf(".");
}
scanf("\n");
printf("\n");
}
}
return 0;
}