day 1
Signed-off-by: Jack Bond-Preston <jackbondpreston@outlook.com>
This commit is contained in:
commit
f7a3960814
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
.vscode
|
||||
input.txt
|
19
1/1a.cpp
Normal file
19
1/1a.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <fstream>
|
||||
#include <climits>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::ifstream infile("input.txt");
|
||||
|
||||
unsigned int curr, prev = UINT_MAX;
|
||||
unsigned int increases = 0;
|
||||
|
||||
while (infile >> curr) {
|
||||
if (curr > prev) ++increases;
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
std::cout << increases << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
29
1/1b.cpp
Normal file
29
1/1b.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <fstream>
|
||||
#include <climits>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
std::ifstream infile("input.txt");
|
||||
|
||||
std::vector<int> window { 0, 0, 0 };
|
||||
int curr = 0;
|
||||
unsigned int increases = 0;
|
||||
|
||||
infile >> window[0];
|
||||
infile >> window[1];
|
||||
infile >> window[2];
|
||||
|
||||
while (infile >> curr) {
|
||||
int prev_sum = window[0] + window[1] + window[2];
|
||||
int new_sum = window[1] + window[2] + curr;
|
||||
|
||||
if (new_sum > prev_sum) ++increases;
|
||||
|
||||
window = { window[1], window[2], curr };
|
||||
}
|
||||
|
||||
std::cout << increases << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user