-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path449.cpp
More file actions
63 lines (56 loc) · 1.23 KB
/
Copy path449.cpp
File metadata and controls
63 lines (56 loc) · 1.23 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
#include<iostream>
#include<string>
using namespace std;
int map[52][52];
int calc(int width, int height) {
int dIO[6] = { 0, 0,-1,-1, 1, 1 };
int dJO[6] = { -1, 1,-1, 0,-1, 0 };
int dIE[6] = { 0, 0,-1,-1, 1, 1 };
int dJE[6] = { -1, 1,1, 0,1, 0 };
int count = 0;
for (int i = 0; i <= height + 1; i++) {
map[i][width + 1] = 1;
}
for (int i = 0; i <= width + 1; i++) {
map[height+1][i] = 1;
}
for (int i = 1; i <= height; i++) {
for (int j = 1; j <= width; j++) {
for (int d = 0; d < 6; d++) {
if ((map[i][j] == 1 && map[i + dIO[d]][j + dJO[d]] == 0 && i % 2 == 1) ||
(map[i][j] == 1 && map[i + dIE[d]][j + dJE[d]] == 0 && i % 2 == 0)) {
count++;
}
}
}
}
return count;
}
int main() {
int width, height;
string input;
memset(map, 0, sizeof(map));
for (int i = 0; i < 52; i++) {
map[i][0] = 1;
map[0][i] = 1;
}
height = 0;
while (getline(cin, input)) {
if (input == "") {
cout << calc(width, height) << endl;
memset(map, 0, sizeof(map));
for (int i = 0; i < 52; i++) {
map[i][0] = 1;
map[0][i] = 1;
}
height = 0;
continue;
}
height++;
width = input.length();
for (int i = 0; i < width; i++) {
map[height][i + 1] = (input[i] == '#' ? 1 : 0);
}
}
return 0;
}