-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_09b.cpp
53 lines (51 loc) · 1.2 KB
/
day_09b.cpp
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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <regex>
int main(int argc, char* argv[]) {
const std::string input = (argc > 1) ? argv[1] : "../input/day_09_input" ;
std::ifstream file(input);
std::string line;
while(std::getline(file, line)) {
int idx = 0;
bool is_in_garbage = false;
int level = 0;
int score = 0;
int groups = 0;
int char_count = 0;
while(idx < line.size()) {
if (!is_in_garbage) {
if (line[idx] == '{') {
level++;
score += level;
groups++;
}
else if (line[idx] == '}') {
level--;
}
else if (line[idx] == '<') {
is_in_garbage = true;
}
} else {
if (line[idx] == '!') {
idx++;
} else if (line[idx] == '>') {
is_in_garbage = false;
} else {
char_count++;
}
}
idx++;
}
std::cout << "groups: " << groups << '\n';
std::cout << "score: " << score << '\n';
std::cout << "char_count: " << char_count << '\n';
std::cout << '\n';
}
return 0;
}