-
Notifications
You must be signed in to change notification settings - Fork 26
/
10141.go
49 lines (43 loc) · 881 Bytes
/
10141.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
// UVa 10141 - Request for Proposal
package main
import (
"bufio"
"fmt"
"math"
"os"
)
func main() {
in, _ := os.Open("10141.in")
defer in.Close()
out, _ := os.Create("10141.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var n, p, kase int
for s.Scan() {
if fmt.Sscanf(s.Text(), "%d%d", &n, &p); n == 0 && p == 0 {
break
}
for i := 0; i < n && s.Scan(); i++ {
}
lowest := math.MaxFloat64
var name, choice string
var max, met int
var price float64
for i := 0; i < p && s.Scan(); i++ {
name = s.Text()
s.Scan()
fmt.Sscanf(s.Text(), "%f%d", &price, &met)
for j := 0; j < met && s.Scan(); j++ {
}
if met > max || met == max && price < lowest {
choice, max, lowest = name, met, price
}
}
kase++
if kase > 1 {
fmt.Fprintln(out)
}
fmt.Fprintf(out, "RFP #%d\n%s\n", kase, choice)
}
}