-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10189.cpp
More file actions
76 lines (63 loc) · 1.18 KB
/
10189.cpp
File metadata and controls
76 lines (63 loc) · 1.18 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
using namespace std;
void solve();
void calc();
int64_t numRows;
int64_t numCols;
int64_t counter = 0;
int64_t field[105][105];
const int64_t di[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int64_t dj[] = {0, -1, 0, 1, -1, 1, 1, -1};
int main() {
while (cin >> numRows >> numCols) {
if ((numRows == 0) && (numCols == 0)) {
break;
} else {
solve();
}
}
return 0;
}
void solve() {
string temp;
for (int64_t i = 1; i <= numRows; i++) {
cin >> temp;
for (int64_t j = 1; j <= numCols; j++) {
if (temp[j - 1] == '.') {
field[i][j] = 0;
} else {
field[i][j] = -100;
}
}
}
calc();
counter++;
if (counter > 1) {
cout << endl;
}
cout << "Field #" << counter << ":" << endl;
for (int64_t i = 1; i <= numRows; i++) {
for (int64_t j = 1; j <= numCols; j++) {
if (field[i][j] >= 0) {
cout << field[i][j];
} else {
cout << '*';
}
}
cout << endl;
}
}
void calc() {
for (int64_t i = 1; i <= numRows; i++) {
for (int64_t j = 1; j <= numCols; j++) {
if (field[i][j] < 0) {
for (int64_t k = 0; k < 8; k++) {
field[i + di[k]][j + dj[k]]++;
}
}
}
}
}