-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10928.go
56 lines (50 loc) · 1 KB
/
10928.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
// UVa 10928 - My Dear Neighbours
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
func solve(places [][]int) []string {
min := math.MaxInt32
for _, place := range places {
if l := len(place); l < min {
min = l
}
}
var placeToBe []string
for i, place := range places {
if l := len(place); l == min {
placeToBe = append(placeToBe, strconv.Itoa(i+1))
}
}
return placeToBe
}
func main() {
in, _ := os.Open("10928.in")
defer in.Close()
out, _ := os.Create("10928.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var n, place, p int
s.Scan()
for fmt.Sscanf(s.Text(), "%d", &n); n > 0 && s.Scan(); n-- {
fmt.Sscanf(s.Text(), "%d", &p)
places := make([][]int, p)
for i := range places {
s.Scan()
for r := strings.NewReader(s.Text()); ; {
if _, err := fmt.Fscanf(r, "%d", &place); err != nil {
break
}
places[i] = append(places[i], place)
}
}
fmt.Fprintln(out, strings.Join(solve(places), " "))
s.Scan()
}
}