summaryrefslogtreecommitdiff
path: root/2022/Day4/main.cpp
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2022-12-04 11:53:33 +0200
committeromagdy7 <omar.professional8777@gmail.com>2022-12-04 11:53:33 +0200
commitb6581928ca05708bc8aa1cc1c2b6ab44e7100a1a (patch)
treec8691a2142d18f8c65967764fe133454c6e755c7 /2022/Day4/main.cpp
parentfc7d21b046fe47f8cb109677866f2c78a6140ffe (diff)
downloadaoc-b6581928ca05708bc8aa1cc1c2b6ab44e7100a1a.tar.xz
aoc-b6581928ca05708bc8aa1cc1c2b6ab44e7100a1a.zip
Day4 done
Diffstat (limited to '2022/Day4/main.cpp')
-rw-r--r--2022/Day4/main.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/2022/Day4/main.cpp b/2022/Day4/main.cpp
new file mode 100644
index 0000000..b511da8
--- /dev/null
+++ b/2022/Day4/main.cpp
@@ -0,0 +1,48 @@
+#include<bits/stdc++.h>
+using namespace std;
+
+struct P2 {
+ int start;
+ int end;
+};
+
+void solve_part_one() {
+ P2 first, second;
+ int ans = 0;
+ while(cin >> first.start >> first.end >> second.start >> second.end) {
+ if ((first.start >= second.start && first.end <= second.end) || (second.start >= first.start && second.end <= first.end)) {
+ ans++;
+ }
+ }
+ cout << ans << '\n';
+}
+
+void solve_part_two() {
+ P2 f, s;
+ int ans = 0;
+ while(cin >> f.start >> f.end >> s.start >> s.end) {
+ vector<int> vis(100, 0);
+ for (int i = f.start; i <= f.end; i++) {
+ vis[i] += 1;
+ }
+ for (int i = s.start; i <= s.end; i++) {
+ vis[i] += 1;
+ }
+ for (int i = 0; i <= vis.size(); i++) {
+ if(vis[i] == 2) {
+ ans++;
+ break;
+ }
+ }
+ }
+ cout << ans << '\n';
+}
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ // solve_part_one();
+ solve_part_two();
+}
+
+