-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVA260.cpp
executable file
·53 lines (49 loc) · 1.3 KB
/
UVA260.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
#include <iostream>
#include <string>
using namespace std;
string matriz[201][201];
string ganador;
const int direcciones[][2] = {{-1,-1},{-1,0},{0,-1},{0,1},{1,0},{1,1}};
void DFS(int n, string letraO, int i, int j){
matriz[i][j] = "";
if(letraO == "w" && j == n - 1){
ganador = "W";
}else if(letraO == "b" && i == n - 1){
ganador = "B";
}
for(int k = 0; k < 6; k++){
int ni = i + direcciones[k][0];
int nj = j + direcciones[k][1];
if (ni < 0 || ni >= n || nj < 0 || nj >= n) continue;
if(matriz[ni][nj] == letraO){
DFS(n, letraO, ni, nj);
}
}
}
int main(){
int n, juego = 1;
string cadena;
while(true){
cin >> n;
if(n == 0) break;
for(int i = 0; i < n; i++){
cin >> cadena;
for(int j = 0; j < n; j++){
matriz[i][j] = cadena.substr(j,1);
}
}
for(int i = 0; i < n; i++){
if(matriz[i][0] == "w"){
DFS(n, "w", i, 0);
}
}
for(int j = 0; j < n; j++){
if(matriz[0][j] == "b"){
DFS(n, "b", 0, j);
}
}
cout << juego << " " << ganador <<endl;
juego++;
}
return 0;
}