-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBeachLength449.cpp
More file actions
88 lines (86 loc) · 2.16 KB
/
BeachLength449.cpp
File metadata and controls
88 lines (86 loc) · 2.16 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
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <cstring>
using namespace std;
char str[200][200] = {'\0'};
int compareRow(int j, int end){
int ctr = 0;
for (int i = 0; i < end-1; i++) {
if ((str[j][i] == '.'&&str[j][i + 1] == '#') || (str[j][i] == '#'&&str[j][i + 1] == '.'))
ctr++;
}
return ctr;
}
int compareBottomRow(int j, int end , int type) {// type is dependant on the hexagonal pattern. if type is 0 the row on the bottm isi shifted to the right
int ctr = 0;
if (type == 0) {
for (int i = 0; i < end; i++) {
if (i == 0) {
if ((str[j][i] == '.'&&str[j + 1][i] == '#') || (str[j][i] == '#'&&str[j + 1][i] == '.'))
ctr++;
}
else {
if ((str[j][i] == '.'&&str[j + 1][i] == '#') || (str[j][i] == '#'&&str[j + 1][i] == '.'))
ctr++;
if ((str[j][i] == '.'&&str[j + 1][i - 1] == '#') || (str[j][i] == '#'&&str[j + 1][i - 1] == '.'))
ctr++;
}
}
}
else if (type == 1) {
for (int i = 0; i < end; i++) {
if (i == end - 1) {
if ((str[j][i] == '.'&&str[j + 1][i] == '#') || (str[j][i] == '#'&&str[j + 1][i] == '.'))
ctr++;
}
else {
if ((str[j][i] == '.'&&str[j + 1][i] == '#') || (str[j][i] == '#'&&str[j + 1][i] == '.'))
ctr++;
if ((str[j][i] == '.'&&str[j + 1][i + 1] == '#') || (str[j][i] == '#'&&str[j + 1][i + 1] == '.'))
ctr++;
}
}
}
return ctr;
}
int main() {
int i = 0;
while (cin.getline(str[i], 51)) {
int sum = 0;
if (str[i][0] == '\0') {
for (int j = 0; j < i; j++) {
sum += compareRow(j, strlen(str[j]));
if (j == 0 && i>1) {
sum += compareBottomRow(j, strlen(str[j]), 0);
}
else if(j!=(i-1)){
if (j % 2 == 0)
sum += compareBottomRow(j, strlen(str[j]), 0);
else
sum += compareBottomRow(j, strlen(str[j]), 1);
}
}
if(i>0)
cout << sum << endl;
i = 0;
sum = 0;
}
else
i++;
}
int sum = 0;
for (int j = 0; j < i; j++) {
sum += compareRow(j, strlen(str[j]));
if (j == 0 && i>1) {
sum += compareBottomRow(j, strlen(str[j]), 0);
}
else if (j != (i - 1)) {
if (j % 2 == 0)
sum += compareBottomRow(j, strlen(str[j]), 0);
else
sum += compareBottomRow(j, strlen(str[j]), 1);
}
}
if(i>0)
cout << sum << endl;
return 0;
}