Solve day 5 part 1

This commit is contained in:
Reimar 2025-12-18 14:21:45 +01:00
parent 58d158e118
commit 83485ca95f

44
day_5.cpp Normal file
View 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;
}