From 40b7af94caba06637a58ec7160e8c925c4ef9c47 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Sun, 1 Dec 2024 21:17:50 -0800 Subject: [PATCH] 2024 day 2 --- 2024/2/main-1.cpp | 29 +++++++++++++++++++++++++++++ 2024/2/main-2.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 2024/2/main-1.cpp create mode 100644 2024/2/main-2.cpp diff --git a/2024/2/main-1.cpp b/2024/2/main-1.cpp new file mode 100644 index 0000000..8527081 --- /dev/null +++ b/2024/2/main-1.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int total = 0; + string line; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + vector t; + while (!l.eof()) { + int x; + l >> x; + t.push_back(x); + } + int pos = (t[1] > t[0]) ? 1 : -1; + for (int i = 0; i < t.size() - 1; i++) { + int diff = (t[i + 1] - t[i]) * pos; + if (diff < 1 || diff > 3) { + goto next; + } + } + total++; + next:; + } + cout << total << '\n'; +} diff --git a/2024/2/main-2.cpp b/2024/2/main-2.cpp new file mode 100644 index 0000000..51f0e29 --- /dev/null +++ b/2024/2/main-2.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; + +bool check(const auto &t) { + int pos = (t[1] > t[0]) ? 1 : -1; + for (int i = 0; i < t.size() - 1; i++) { + int diff = (t[i + 1] - t[i]) * pos; + if (diff < 1 || diff > 3) { + return false; + } + } + return true; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int total = 0; + string line; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + vector t; + while (!l.eof()) { + int x; + l >> x; + t.push_back(x); + } + if (check(t)) { + total++; + } else { + for (int i = 0; i < t.size(); i++) { + vector tt; + for (int j = 0; j < t.size(); j++) { + if (j == i) + continue; + tt.push_back(t[j]); + } + if (check(tt)) { + total++; + break; + } + } + } + } + cout << total << '\n'; +}