Solve day 5 part 1
This commit is contained in:
parent
58d158e118
commit
83485ca95f
44
day_5.cpp
Normal file
44
day_5.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct range
|
||||||
|
{
|
||||||
|
long int min;
|
||||||
|
long int max;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::ifstream file("input.txt");
|
||||||
|
|
||||||
|
std::vector<range> fresh_ranges;
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (getline(file, line)) {
|
||||||
|
if (line == "") break;
|
||||||
|
|
||||||
|
range range;
|
||||||
|
sscanf(line.c_str(), "%ld-%ld", &range.min, &range.max);
|
||||||
|
|
||||||
|
fresh_ranges.push_back(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fresh_amount = 0;
|
||||||
|
|
||||||
|
while (getline(file, line)) {
|
||||||
|
long int id = std::stol(line);
|
||||||
|
bool is_fresh = false;
|
||||||
|
|
||||||
|
for (range range : fresh_ranges) {
|
||||||
|
if (id >= range.min && id <= range.max) {
|
||||||
|
is_fresh = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_fresh) fresh_amount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << fresh_amount << std::endl;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user