-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path344.go
More file actions
72 lines (65 loc) · 1.03 KB
/
344.go
File metadata and controls
72 lines (65 loc) · 1.03 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
// UVa 344 - Roman Digititis
package main
import (
"fmt"
"io"
"os"
"strings"
)
var (
num = map[int]string{
0: "",
1: "i",
2: "ii",
3: "iii",
4: "iv",
5: "v",
6: "vi",
7: "vii",
8: "viii",
9: "ix",
10: "x",
20: "xx",
30: "xxx",
40: "xl",
50: "l",
60: "lx",
70: "lxx",
80: "lxxx",
90: "xc",
100: "c",
}
romes = []byte{'i', 'v', 'x', 'l', 'c'}
)
func solve(n int) string {
if str, ok := num[n]; ok {
return str
}
return num[n/10*10] + num[n%10]
}
func output(out io.Writer, n int) {
dict := make(map[byte]int)
for i := 1; i <= n; i++ {
for _, v := range solve(i) {
dict[byte(v)]++
}
}
stats := make([]string, 5)
for i, r := range romes {
stats[i] = fmt.Sprintf("%d %c", dict[r], r)
}
fmt.Fprintf(out, "%d: %s\n", n, strings.Join(stats, ", "))
}
func main() {
in, _ := os.Open("344.in")
defer in.Close()
out, _ := os.Create("344.out")
defer out.Close()
var n int
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
output(out, n)
}
}