blob: df02c81a494746f4e76f930f7fac2ef3c36eb868 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <cstdio>
using namespace std;
struct
Range {
int from, to;
bool
contains(Range &other) {
return this->from <= other.from && other.to <= this->to;
}
bool
contains(int n) {
return this->from <= n && n <= this->to;
}
bool
overlaps(Range &other) {
return this->contains(other.from)
|| this->contains(other.to)
|| other.contains(this->from)
|| other.contains(this->to);
}
};
int
main()
{
Range a, b;
int total1 = 0;
int total2 = 0;
while (scanf("%d-%d,%d-%d ", &a.from, &a.to, &b.from, &b.to) == 4) {
if (a.contains(b) || b.contains(a))
total1++;
if (a.overlaps(b))
total2++;
}
printf("%d\n", total1);
printf("%d\n", total2);
}
|