-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday04.cpp
More file actions
65 lines (61 loc) 路 1.8 KB
/
Copy pathday04.cpp
File metadata and controls
65 lines (61 loc) 路 1.8 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
#include <iostream>
#include <fstream>
#include <string>
int main() {
long count = 0;
std::ifstream file("input.txt");
std::string str0;
std::string str1;
std::string str2;
bool oneMoreLine = true;
while (std::getline(file, str2) || oneMoreLine)
{
if (str1.empty()) {
str1 = str2;
std::getline(file, str2);
} else if (str2.empty()) {
oneMoreLine = false;
}
int rollCount = 0;
for (int pos = 0; pos < str1.length(); pos++) {
if (str1[pos] == '@') {
if (pos > 0) {
if (str1[pos - 1] == '@') {
rollCount++;
}
if (oneMoreLine && str2[pos - 1] == '@') {
rollCount++;
}
if (!str0.empty() && str0[pos - 1] == '@') {
rollCount++;
}
}
if (pos < str1.length()) {
if (str1[pos + 1] == '@') {
rollCount++;
}
if (oneMoreLine && str2[pos + 1] == '@') {
rollCount++;
}
if (!str0.empty() && str0[pos + 1] == '@') {
rollCount++;
}
}
if (oneMoreLine && str2[pos] == '@') {
rollCount++;
}
if (!str0.empty() && str0[pos] == '@') {
rollCount++;
}
if (rollCount < 4) {
count++;
}
rollCount = 0;
}
}
str0 = str1;
str1 = str2;
}
std::cout << count << std::endl;
return 0;
}