-
Notifications
You must be signed in to change notification settings - Fork 27
/
340.go
60 lines (54 loc) · 945 Bytes
/
340.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
54
55
56
57
58
59
60
// UVa 340 - Master-Mind Hints
package main
import (
"fmt"
"os"
)
func match(s, g []int) (int, int) {
ms, mg := make(map[int]int), make(map[int]int)
strong, weak := 0, 0
for i, v := range s {
if g[i] == v {
strong++
} else {
ms[v]++
mg[g[i]]++
}
}
for i, vi := range ms {
vj := mg[i]
weak += min(vi, vj)
}
return strong, weak
}
func main() {
in, _ := os.Open("340.in")
defer in.Close()
out, _ := os.Create("340.out")
defer out.Close()
var n int
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
fmt.Fprintf(out, "Game %d:\n", kase)
s, g := make([]int, n), make([]int, n)
for i := range s {
fmt.Fscanf(in, "%d", &s[i])
}
for {
stop := true
for i := range g {
fmt.Fscanf(in, "%d", &g[i])
if g[i] != 0 {
stop = false
}
}
if stop {
break
}
strong, weak := match(s, g)
fmt.Fprintf(out, " (%d,%d)\n", strong, weak)
}
}
}