-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path260.go
53 lines (46 loc) · 780 Bytes
/
260.go
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
// UVa 260 - Il Gioco dell'X
package main
import (
"fmt"
"os"
)
var (
n int
board [][]byte
)
func dfs(i, j int) bool {
if j >= n || board[i][j] != 'b' {
return false
}
return i == n-1 || dfs(i+1, j) || dfs(i+1, j+1)
}
func blackWins() bool {
for j := range board {
if dfs(0, j) {
return true
}
}
return false
}
func main() {
in, _ := os.Open("260.in")
defer in.Close()
out, _ := os.Create("260.out")
defer out.Close()
var line string
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
board = make([][]byte, n)
for i := range board {
fmt.Fscanf(in, "%s", &line)
board[i] = []byte(line)
}
if fmt.Fprint(out, kase); blackWins() {
fmt.Fprintln(out, " B")
} else {
fmt.Fprintln(out, " W")
}
}
}