-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_02b.cpp
More file actions
30 lines (27 loc) · 773 Bytes
/
day_02b.cpp
File metadata and controls
30 lines (27 loc) · 773 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
30
#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));
if (line[2] == 'X') {
score += (line[0] - 'A' - 1 + 3) % 3 + 1;
} else if (line[2] == 'Y') {
score += 3 + line[0] - 'A' + 1;
} else {
score += 6 + (line[0] - 'A' + 1) % 3 + 1;
}
}
std::cout << score << '\n';
return 0;
}