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
|
#include <cstdio>
using namespace std;
bool
range_contains(int a1, int a2, int b1, int b2)
{
return a1 <= b1 && b2 <= a2;
}
bool
range_in(int a1, int a2, int v)
{
return a1 <= v && v <= a2;
}
bool
range_overlap(int a1, int a2, int b1, int b2)
{
return range_in(a1, a2, b1) || range_in(a1, a2, b2) || range_in(b1, b2, a1) || range_in(b1, b2, a2);
}
int
main()
{
int a1, a2, b1, b2;
int total1 = 0;
int total2 = 0;
while (scanf("%d-%d,%d-%d ", &a1, &a2, &b1, &b2) == 4) {
if (range_contains(a1, a2, b1, b2) || range_contains(b1, b2, a1, a2))
total1++;
if (range_overlap(a1, a2, b1, b2))
total2++;
}
printf("%d\n", total1);
printf("%d\n", total2);
}
|