-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_02a.cpp
More file actions
29 lines (26 loc) · 738 Bytes
/
day_02a.cpp
File metadata and controls
29 lines (26 loc) · 738 Bytes
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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char * argv[]) {
std::string input = "../input/day_02_input";
if (argc > 1) {
input = argv[1];
}
std::string line;
std::fstream file(input);
int score = 0;
while(std::getline(file, line)) {
// Account for CRLF if required
// line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line));
score += line[2] - 'X' + 1;
if (const auto delta = (line[2] - line[0] - 23 + 3) % 3; delta == 1) {
score += 6;
} else if (delta == 0) {
score += 3;
}
}
std::cout << score << '\n';
return 0;
}