-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_08b.cpp
34 lines (30 loc) · 838 Bytes
/
day_08b.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
#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 = 0; i < line.size(); i++) {
if (std::isalnum(line[i])) {
just_chars += line[i];
} else {
just_chars += "\\" + std::string{line[i]};
}
}
just_chars = '\"' + just_chars + '\"';
return just_chars.size() - line.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;
}