From 8be933143d9c3bca3a5473278bb8e31496ef108d Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 4 Dec 2022 11:41:49 +0100 Subject: day 4 initial solution --- 22.4/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 22.4/main.cpp (limited to '22.4') 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 +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); +} -- cgit 1.4.1-2-gfad0