/home/toolbox/public_html/solutions/101/10189/minesweep.cpp
1 #include <cstdio>
2 #include <iostream>
3
4 int rangex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
5 int rangey[8] = {0, -1, -1, -1, 0, 1, 1, 1};
6
7 int map[102][102];
8 const char bomb = '*';
9
10 void floodfill(int x, int y)
11 {
12 for (int i = 0; i < 8; ++i)
13 {
14 if (bomb != map[x+rangex[i]][y+rangey[i]])
15 ++map[x+rangex[i]][y+rangey[i]];
16 }
17 }
18
19 int main()
20 {
21 char dummy;
22 int width, height;
23 int counter = 1;
24 scanf("%d %d ", &height, &width);
25 while ((width != 0) and (height != 0))
26 {
27 //zero out the map
28 memset(map, 0, sizeof(int)*102*102);
29
30 for (int i = 1; i < width+1; ++i)
31 {
32 for (int j = 1; j < height+1; ++j)
33 {
34 scanf("%c", &map[i][j]);
35 if (map[i][j] != bomb) map[i][j] = 0;
36 }
37 scanf("%c", &dummy);
38 }
39
40 for (int i = 1; i < width+1; ++i)
41 for (int j = 1; j < height+1; ++j)
42 if (bomb == map[i][j])
43 floodfill(i, j);
44
45 //output
46 printf("Field #%d:\n", counter++);
47 for (int i = 1; i < width+1; ++i)
48 {
49 for (int j = 1; j < height+1; ++j)
50 if (map[i][j] != bomb)
51 printf("%d", map[i][j]);
52 else
53 printf("%c", bomb);
54
55 printf("\n");
56 }
57
58 printf("\n");
59 scanf("%d %d ", &width, &height);
60 }
61
62 return 0;
63 }
64
65