diff --git a/day_5.cpp b/day_5.cpp new file mode 100644 index 0000000..2c409e2 --- /dev/null +++ b/day_5.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +struct range +{ + long int min; + long int max; +}; + +int main() +{ + std::ifstream file("input.txt"); + + std::vector 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; +}