-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path119.go
59 lines (52 loc) · 1.06 KB
/
119.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
// UVa 119 - Greedy Gift Givers
package main
import (
"fmt"
"os"
)
type giver struct {
name string
amount int
toList []string
}
func main() {
in, _ := os.Open("119.in")
defer in.Close()
out, _ := os.Create("119.out")
defer out.Close()
var n, num int
for first := true; ; {
if _, err := fmt.Fscanf(in, "%d", &n); err != nil {
break
}
names := make([]string, n)
for i := range names {
fmt.Fscanf(in, "%s", &names[i])
}
givers := make([]giver, n)
table := make(map[string]int)
for i := range givers {
fmt.Fscanf(in, "%s%d%d", &givers[i].name, &givers[i].amount, &num)
if num != 0 {
table[givers[i].name] = -(givers[i].amount / num) * num
}
givers[i].toList = make([]string, num)
for j := range givers[i].toList {
fmt.Fscanf(in, "%s", &givers[i].toList[j])
}
}
for _, fm := range givers {
for _, to := range fm.toList {
table[to] += fm.amount / len(fm.toList)
}
}
if first {
first = false
} else {
fmt.Fprintln(out)
}
for _, v := range names {
fmt.Fprintln(out, v, table[v])
}
}
}