-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4p2.cpp
More file actions
43 lines (39 loc) · 876 Bytes
/
day4p2.cpp
File metadata and controls
43 lines (39 loc) · 876 Bytes
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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int r, c;
int check(vector<string> &puzzle, int x, int y)
{
if (x == 0 || x == r || y == 0 || y == r || puzzle[x][y] != 'A')
return 0;
char tl = puzzle[x-1][y-1];
char tr = puzzle[x-1][y+1];
char bl = puzzle[x+1][y-1];
char br = puzzle[x+1][y+1];
if ((tl != 'M' || br != 'S') && (tl != 'S' || br != 'M'))
return 0;
if ((tr != 'M' || bl != 'S') && (tr != 'S' || bl != 'M'))
return 0;
return 1;
}
int main()
{
vector<string> puzzle;
ifstream input_file("input.txt");
string line;
while (getline(input_file, line))
puzzle.push_back(line);
r = puzzle.size();
c = puzzle[0].size();
int ans = 0;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
ans += check(puzzle, i, j);
}
}
cout << ans << endl;
}