-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10424.go
53 lines (47 loc) · 815 Bytes
/
10424.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
// UVa 10424 - Love Calculator
package main
import (
"bufio"
"fmt"
"io"
"os"
)
func value(name string) int {
v := 0
for i := range name {
switch {
case name[i] >= 'a' && name[i] <= 'z':
v += int(name[i]-'a') + 1
case name[i] >= 'A' && name[i] <= 'Z':
v += int(name[i]-'A') + 1
}
}
for v > 9 {
sum := 0
for v > 0 {
sum += v % 10
v /= 10
}
v = sum
}
return v
}
func solve(out io.Writer, n1, n2 string) {
v1 := value(n1)
v2 := value(n2)
fmt.Fprintf(out, "%.2f %%\n", float64(min(v1, v2)*100)/float64(max(v1, v2)))
}
func main() {
in, _ := os.Open("10424.in")
defer in.Close()
out, _ := os.Create("10424.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
for s.Scan() {
n1 := s.Text()
s.Scan()
n2 := s.Text()
solve(out, n1, n2)
}
}