-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_04b.cpp
44 lines (39 loc) · 1.27 KB
/
day_04b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <array>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
int check(const std::vector<std::string>& map, const int row, const int col) {
int total = 0;
static constexpr std::array<int, 2> move = {1,1};
if (map[row][col] == 'A' &&
((map[row + move[0]][col + move[1]] == 'M' && map[row - move[0]][col - move[1]] == 'S') ||
(map[row - move[0]][col - move[1]] == 'M' && map[row + move[0]][col + move[1]] == 'S')) &&
((map[row + move[0]][col - move[1]] == 'M' && map[row - move[0]][col + move[1]] == 'S') ||
(map[row - move[0]][col + move[1]] == 'M' && map[row + move[0]][col - move[1]] == 'S'))) {
total += 1;
}
return total;
}
int main(int argc, char* argv[]) {
std::string input = "../input/day_04_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
std::vector<std::string> map;
while(std::getline(file, line)) {
map.push_back(line);
}
int total = 0;
for (int i = 1; i < map.size()-1; i++) {
for (int j = 1; j < map[0].size()-1; j++) {
if (map[i][j] == 'A') {
total += check(map, i, j);
}
}
}
std::cout << total << '\n';
return 0;
}