-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.cpp
106 lines (101 loc) · 2.67 KB
/
go.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <fstream>
#include <iostream>
using namespace std;
ifstream input("go.inp");
ofstream output("go.out");
char **arr;
int **visit;
int cnt;
int temp;
char tmp;
int black, white;
void check(int a, int b) {
if (visit[a][b] == 0) {
if (arr[a][b] == '.') {
visit[a][b] = 1;
if (temp != -1) {
temp++;
}
if (a+1 != cnt) {
if (arr[a + 1][b] == '.') {
check(a + 1, b);
} else {
if (tmp == ' ') {
tmp = arr[a + 1][b];
} else {
if (arr[a + 1][b] != tmp)
temp = -1;
}
}
}
if (b+1 != cnt) {
if (arr[a][b + 1] == '.') {
check(a, b + 1);
} else {
if (tmp == ' ') {
tmp = arr[a][b + 1];
} else {
if (arr[a][b + 1] != tmp)
temp = -1;
}
}
}
if (a != 0) {
if (arr[a - 1][b] == '.') {
check(a - 1, b);
} else {
if (tmp == ' ') {
tmp = arr[a - 1][b];
} else {
if (arr[a - 1][b] != tmp)
temp = -1;
}
}
}
if (b != 0) {
if (arr[a][b - 1] == '.') {
check(a, b - 1);
} else {
if (tmp == ' ') {
tmp = arr[a][b - 1];
} else {
if (arr[a][b - 1] != tmp)
temp = -1;
}
}
}
}
}
}
int main() {
input >> cnt;
arr = new char *[cnt];
visit = new int *[cnt];
for (int i = 0; i < cnt; i++) {
arr[i] = new char[cnt];
visit[i] = new int[cnt];
}
char c;
for (int i = 0; i < cnt; i++) {
for (int j = 0; j < cnt; j++) {
input >> c;
arr[i][j] = c;
visit[i][j] = 0;
}
}
for (int i = 0; i < cnt; i++) {
for (int j = 0; j < cnt; j++) {
temp = 0;
tmp = ' ';
check(i, j);
if (temp != -1) {
if (tmp == 'B') {
black += temp;
} else if (tmp == 'W') {
white += temp;
}
}
}
}
output << black << " " << white;
}