Finished day 4 aoc
This commit is contained in:
1000
advent_of_code/2022/4/input.txt
Normal file
1000
advent_of_code/2022/4/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
27
advent_of_code/2022/4/main.cpp
Normal file
27
advent_of_code/2022/4/main.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ifstream input_file("input.txt");
|
||||||
|
string line;
|
||||||
|
unsigned int score = 0;
|
||||||
|
|
||||||
|
while(getline(input_file, line)){
|
||||||
|
stringstream ss(line);
|
||||||
|
|
||||||
|
int x, y, a, b;
|
||||||
|
char leftovers;
|
||||||
|
ss >> x >> leftovers >> y >> leftovers >> a >> leftovers >> b;
|
||||||
|
|
||||||
|
// cout << x << "-" << y << "," << a << "-" << b << endl;
|
||||||
|
|
||||||
|
if((x <= a && y >= a) || (a <= x && b >= x)){
|
||||||
|
score++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Score: " << score << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
advent_of_code/2022/4/test.txt
Normal file
6
advent_of_code/2022/4/test.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8
|
||||||
Reference in New Issue
Block a user