-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_01b.cpp
More file actions
38 lines (36 loc) · 760 Bytes
/
day_01b.cpp
File metadata and controls
38 lines (36 loc) · 760 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
31
32
33
34
35
36
37
38
#include <fstream>
#include <iostream>
#include <string>
#include <queue>
int main(int argc, char * argv[]) {
std::string input = "../input/day_01_input";
if (argc > 1) {
input = argv[1];
}
std::string line;
std::fstream file(input);
std::queue<int> window;
constexpr int n = 3;
int cur = 0;
for (int i = 0; i < n; i++) {
std::getline(file, line);
const int temp = std::stoi(line);
window.push(temp);
cur += temp;
}
int prev = cur;
int count = 0;
while(std::getline(file, line)) {
prev = cur;
cur -= window.front();
window.pop();
const int temp = std::stoi(line);
cur += temp;
window.push(temp);
if (cur > prev) {
count++;
}
}
std::cout << count << '\n';
return 0;
}