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'; +}