Day 5 Question 1
This commit is contained in:
1187
Day5/Question1/input
Normal file
1187
Day5/Question1/input
Normal file
File diff suppressed because it is too large
Load Diff
11
Day5/Question1/inputTest
Normal file
11
Day5/Question1/inputTest
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
43
Day5/Question1/main.cpp
Normal file
43
Day5/Question1/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Range {
|
||||||
|
uint64_t lowerInclusiveBound = 0;
|
||||||
|
uint64_t upperInclusiveBound = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::fstream input("input");
|
||||||
|
std::string currentLine = "";
|
||||||
|
std::getline(input, currentLine, '\n');
|
||||||
|
std::vector<Range> ranges{};
|
||||||
|
uint16_t positionOfHypen = 0;
|
||||||
|
|
||||||
|
// Range and values are seperated by an empty \n
|
||||||
|
while (currentLine != "") {
|
||||||
|
positionOfHypen = currentLine.find('-');
|
||||||
|
// Sorry its ugly but it just gets the numbers
|
||||||
|
ranges.push_back({std::stoull(currentLine.substr(0, positionOfHypen)),
|
||||||
|
std::stoull(currentLine.substr(positionOfHypen + 1))});
|
||||||
|
|
||||||
|
std::getline(input, currentLine, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t currentProduceID = 0, freshProduceCount = 0;
|
||||||
|
while (std::getline(input, currentLine, '\n')) {
|
||||||
|
currentProduceID = std::stoull(currentLine);
|
||||||
|
for (Range currentRange : ranges) {
|
||||||
|
if (currentRange.lowerInclusiveBound <= currentProduceID &&
|
||||||
|
currentProduceID <= currentRange.upperInclusiveBound) {
|
||||||
|
freshProduceCount++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << freshProduceCount << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user