-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.cpp
More file actions
84 lines (76 loc) · 2.87 KB
/
10.cpp
File metadata and controls
84 lines (76 loc) · 2.87 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <fstream>
#include <iostream>
#include <set>
using namespace std;
int X = 40;
int Y = 40;
int main(){
ifstream in("Input.txt");
int map[X][Y];
string lineTmp;
int y = 0;
while (getline(in, lineTmp)) {
int x = 0;
for (char a : lineTmp) {
map[x][y] = a - '0';
x++;
}
y++;
}
int sum = 0;
for (int y = 0; y < Y; y++) {
for (int x = 0; x < X; x++) {
if (map[x][y] == 0) {
queue<pair<int, int>> posToCheck;
posToCheck.emplace(x, y);
while (!posToCheck.empty()) {
auto pos = posToCheck.front();
posToCheck.pop();
int value = map[pos.first][pos.second];
value++;
auto checkedPos = make_pair(pos.first + 1, pos.second);
if (checkedPos.first < 0 || checkedPos.first >= X || checkedPos.second < 0 || checkedPos.second >= Y) {
}
else if (map[checkedPos.first][checkedPos.second] == value) {
if (value == 9) {
sum++;
} else {
posToCheck.push(checkedPos);
}
}
checkedPos = make_pair(pos.first - 1, pos.second);
if (checkedPos.first < 0 || checkedPos.first >= X || checkedPos.second < 0 || checkedPos.second >= Y) {
}
else if (map[checkedPos.first][checkedPos.second] == value) {
if (value == 9) {
sum++;
} else {
posToCheck.push(checkedPos);
}
}
checkedPos = make_pair(pos.first, pos.second + 1);
if (checkedPos.first < 0 || checkedPos.first >= X || checkedPos.second < 0 || checkedPos.second >= Y) {
}
else if (map[checkedPos.first][checkedPos.second] == value) {
if (value == 9) {
sum++;
} else {
posToCheck.push(checkedPos);
}
}
checkedPos = make_pair(pos.first, pos.second - 1);
if (checkedPos.first < 0 || checkedPos.first >= X || checkedPos.second < 0 || checkedPos.second >= Y) {
}
else if (map[checkedPos.first][checkedPos.second] == value) {
if (value == 9) {
sum++;
} else {
posToCheck.push(checkedPos);
}
}
}
}
}
}
cout << sum;
}