diff options
author | dzwdz | 2022-12-04 11:41:49 +0100 |
---|---|---|
committer | dzwdz | 2022-12-04 11:41:49 +0100 |
commit | 8be933143d9c3bca3a5473278bb8e31496ef108d (patch) | |
tree | fe93aa1e5362b4c7bc2d78c749b9bd0412fa2e9c /22.4/main.cpp | |
parent | 7ce14487c506b7086d1cac7e16918551e1859883 (diff) |
day 4 initial solution
Diffstat (limited to '22.4/main.cpp')
-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); +} |