-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_13a.cpp
40 lines (38 loc) · 1.08 KB
/
day_13a.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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <regex>
#include <cmath>
#include <queue>
void parse_input(const std::string& line, std::unordered_map<int, int>& map) {
std::size_t start = 0;
const std::string delimiter = ": ";
std::size_t end = line.find(delimiter);
const auto depth = std::stoi(line.substr(start, end - start));
start = end + delimiter.size();
end = line.find(delimiter, start);
const auto range = std::stoi(line.substr(start, end - start));
map[depth] = range;
}
int main(int argc, char* argv[]) {
const std::string input = (argc > 1) ? argv[1] : "../input/day_13_input" ;
std::ifstream file(input);
std::string line;
std::unordered_map<int, int> map;
while(std::getline(file, line)) {
parse_input(line, map);
}
int total_severity = 0;
for (const auto& [depth, range] : map) {
if (depth % ((range - 1) * 2) == 0) {
total_severity += depth * range;
}
}
std::cout << total_severity << '\n';
return 0;
}