2024 day 4: C++ solution
This is just the Haskell solution but better because that was so imperative anyways
This commit is contained in:
parent
b2b1345436
commit
028b1536f7
29
2024/4/main-2.cpp
Normal file
29
2024/4/main-2.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <bits/stdc++.h>
|
||||
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<string> 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';
|
||||
}
|
Loading…
Reference in a new issue