-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_08a.cpp
43 lines (39 loc) · 1.09 KB
/
day_08a.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
#include <fstream>
#include <iostream>
#include <string>
// Make sure that the line ending are accurate (let to LF instead of CRLF)
int parse_line_and_get_delta(const std::string& line) {
std::string just_chars = "";
for (int i = 1; i < line.size()-1; i++) {
if (line[i] != '\\') {
just_chars += line[i];
}
else if (line[i+1] == 'x') {
std::string hex_value = line.substr(i + 2, 2);
int num = std::stoi(hex_value, 0, 16);
char c = char(num);
just_chars += (c);
i+=3;
} else {
just_chars += line[i+1];
i++;
}
}
// std::cout << line << '\n';
// std::cout << just_chars << '\n';
return line.size() - just_chars.size();
}
int main(int argc, char* argv[]) {
std::string input = "../input/day_08_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
int total = 0;
while(std::getline(file, line)) {
total += parse_line_and_get_delta(line);
}
std::cout << total << '\n';
return 0;
}