diff options
Diffstat (limited to '22.4')
-rw-r--r-- | 22.4/main.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/22.4/main.cpp b/22.4/main.cpp new file mode 100644 index 0000000..cf7f9c0 --- /dev/null +++ b/22.4/main.cpp @@ -0,0 +1,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); +} |