-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path626.go
47 lines (42 loc) · 838 Bytes
/
626.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
// UVa 626 - Ecosystem
package main
import (
"fmt"
"io"
"os"
)
func solve(out io.Writer, matrix [][]bool) {
var count int
for i := range matrix {
for j := range matrix {
for k := range matrix {
if matrix[i][j] && matrix[j][k] && matrix[k][i] && (i > j && j > k || i < j && j < k) {
count++
fmt.Fprintf(out, "%d %d %d\n", i+1, j+1, k+1)
}
}
}
}
fmt.Fprintf(out, "total:%d\n\n", count)
}
func main() {
in, _ := os.Open("626.in")
defer in.Close()
out, _ := os.Create("626.out")
defer out.Close()
var n, tmp int
for {
if _, err := fmt.Fscanf(in, "%d", &n); err != nil {
break
}
matrix := make([][]bool, n)
for i := range matrix {
matrix[i] = make([]bool, n)
for j := range matrix[i] {
fmt.Fscanf(in, "%d", &tmp)
matrix[i][j] = tmp == 1
}
}
solve(out, matrix)
}
}