This commit is contained in:
Hugo Mårdbrink 2022-12-04 13:38:07 +01:00
parent b73f4864b8
commit e35f004445
3 changed files with 1034 additions and 0 deletions

View file

@ -12,3 +12,4 @@ endif()
add_executable(d1 "d1/main.cxx")
add_executable(d2 "d2/main.cxx")
add_executable(d3 "d3/main.cxx")
add_executable(d4 "d4/main.cxx")

1000
d4/input.txt Normal file

File diff suppressed because it is too large Load diff

33
d4/main.cxx Normal file
View file

@ -0,0 +1,33 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
std::ifstream file{"../d4/input.txt"};
uint32_t pairs{0};
std::string line;
while (std::getline(file, line))
{
std::string fst{line.substr(0, line.find(','))}, snd{line.substr(line.find(',') + 1)};
fst = fst.replace(fst.find("-"), 1, " ");
snd = snd.replace(snd.find("-"), 1, " ");
uint32_t fl, fh, sl, sh;
std::stringstream fstSs(fst), sndSs(snd);
fstSs >> fl >> fh;
sndSs >> sl >> sh;
if (!(fh < sl || sh < fl))
pairs++;
}
std::cout << pairs << std::endl;
return 0;
}