Day 4
This commit is contained in:
parent
b73f4864b8
commit
e35f004445
3 changed files with 1034 additions and 0 deletions
1000
d4/input.txt
Normal file
1000
d4/input.txt
Normal file
File diff suppressed because it is too large
Load diff
33
d4/main.cxx
Normal file
33
d4/main.cxx
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue