Day 4
This commit is contained in:
parent
63db42f55a
commit
78e28f6959
|
@ -0,0 +1,33 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
string::size_type n = line.find(',');
|
||||||
|
string half1 = line.substr(0,n);
|
||||||
|
string half2 = line.substr(n+1);
|
||||||
|
|
||||||
|
n = half1.find('-');
|
||||||
|
int half1_start = stoi(half1.substr(0,n));
|
||||||
|
int half1_end = stoi(half1.substr(n+1));
|
||||||
|
|
||||||
|
n = half2.find('-');
|
||||||
|
int half2_start = stoi(half2.substr(0,n));
|
||||||
|
int half2_end = stoi(half2.substr(n+1));
|
||||||
|
|
||||||
|
if ((half1_start <= half2_start && half1_end >= half2_end) ||
|
||||||
|
(half2_start <= half1_start && half2_end >= half1_end))
|
||||||
|
{
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
string::size_type n = line.find(',');
|
||||||
|
string half1 = line.substr(0,n);
|
||||||
|
string half2 = line.substr(n+1);
|
||||||
|
|
||||||
|
n = half1.find('-');
|
||||||
|
int half1_start = stoi(half1.substr(0,n));
|
||||||
|
int half1_end = stoi(half1.substr(n+1));
|
||||||
|
|
||||||
|
n = half2.find('-');
|
||||||
|
int half2_start = stoi(half2.substr(0,n));
|
||||||
|
int half2_end = stoi(half2.substr(n+1));
|
||||||
|
|
||||||
|
if (!(half1_end < half2_start || half2_end < half1_start))
|
||||||
|
{
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
Loading…
Reference in New Issue