From 028b1536f74cc1eb8ada2da8be7acfa8040962a2 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Wed, 4 Dec 2024 15:19:52 -0800 Subject: [PATCH] 2024 day 4: C++ solution This is just the Haskell solution but better because that was so imperative anyways --- 2024/4/main-2.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2024/4/main-2.cpp diff --git a/2024/4/main-2.cpp b/2024/4/main-2.cpp new file mode 100644 index 0000000..74f8253 --- /dev/null +++ b/2024/4/main-2.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +inline bool isMas(char a, char b) { + return (a == 'M' && b == 'S') || (a == 'S' && b == 'M'); +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector lines; + string line; + while (getline(cin, line) && !line.empty()) { + lines.push_back(line); + } + + int n = 0; + for (int x = 1; x < lines.size() - 1; x++) { + for (int y = 1; y < lines[x].size() - 1; y++) { + if (lines[x][y] == 'A' && + isMas(lines[x - 1][y - 1], lines[x + 1][y + 1]) && + isMas(lines[x - 1][y + 1], lines[x + 1][y - 1])) { + n++; + } + } + } + cout << n << '\n'; +}