day01
This commit is contained in:
parent
bed3025425
commit
dcd83c8a2f
45
2021/day01.cpp
Normal file
45
2021/day01.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc <= 1) {
|
||||||
|
cerr << "No input file was given!" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ifstream input;
|
||||||
|
input.open(argv[1]);
|
||||||
|
if (input.is_open()) {
|
||||||
|
vector<int> array;
|
||||||
|
int x, y, count;
|
||||||
|
while (input >> x) {
|
||||||
|
array.push_back(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (unsigned int i = 0; i < array.size() - 1; ++i) {
|
||||||
|
if (array[i + 1] > array[i]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << count << endl;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (unsigned int i = 0; i < array.size() - 3; ++i) {
|
||||||
|
y = array[i] + array[i + 1] + array[i + 2];
|
||||||
|
x = array[i + 1] + array[i + 2] + array[i + 3];
|
||||||
|
if (x > y) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << count << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cerr << "Unable to open file!";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
input.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
2000
2021/input/day01.txt
Normal file
2000
2021/input/day01.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user