This commit is contained in:
limb
2021-12-01 19:58:41 +00:00
parent 904c8fe3c7
commit 8627c889d1
4 changed files with 2082 additions and 0 deletions

39
day1/part2/main.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include <iostream>
#include <fstream>
#include <numeric>
using namespace std;
int main() {
cout << "Advent of Code 2021 - Day 1 Part 2" << endl;
ifstream filein("input");
string line;
int firstSlice[3], secondSlice[3];
for(int i = 0; i < 3; i++) {
getline(filein, line);
firstSlice[i] = stoi(line);
}
int count = 0;
while (getline(filein, line))
{
for(int i = 1; i < 3; i++) {
secondSlice[i-1] = firstSlice[i];
}
secondSlice[2] = stoi(line);
if(accumulate(secondSlice,secondSlice+3, 0) > accumulate(firstSlice,firstSlice+3, 0)) {
count++;
}
copy(begin(secondSlice), end(secondSlice), begin(firstSlice));
}
cout << count << endl;
return 0;
}