-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_09_1.cc
58 lines (53 loc) · 1.24 KB
/
puzzle_09_1.cc
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
#include <algorithm>
#include <boost/functional/hash.hpp>
#include <iostream>
#include <sstream>
#include <unordered_set>
#include <vector>
size_t checksum(const std::vector<int>& nums)
{
size_t seed = 0;
for (auto n : nums) {
boost::hash_combine(seed, n);
}
return seed;
}
int main()
{
std::string line;
while (std::getline(std::cin, line)) {
int level = 0;
int sum = 0;
bool skip = false;
bool garbage = false;
for (auto it = std::cbegin(line); it != std::cend(line); ++it) {
if (skip) {
skip = false;
continue;
}
if (*it == '!') {
skip = true;
continue;
}
if (garbage) {
if (*it == '>') {
garbage = false;
}
continue;
}
if (*it == '<') {
garbage = true;
continue;
}
if (*it == '}') {
sum += level--;
continue;
}
if (*it == '{') {
++level;
continue;
}
}
std::cout << "score : " << sum << "\n";
}
}