-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path11541.go
More file actions
43 lines (37 loc) · 854 Bytes
/
11541.go
File metadata and controls
43 lines (37 loc) · 854 Bytes
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
// UVa 11541 - Decoding
package main
import (
"fmt"
"os"
"strings"
"unicode"
)
var (
char = func(c rune) bool { return !unicode.IsLetter(c) }
number = func(c rune) bool { return !unicode.IsNumber(c) }
)
func decode(line string) []string {
numbers := strings.FieldsFunc(line, number)
num := make([]int, len(numbers))
for i, n := range numbers {
fmt.Sscanf(n, "%d", &num[i])
}
token := make([]string, len(num))
for i, c := range strings.FieldsFunc(line, char) {
token[i] = strings.Repeat(c, num[i])
}
return token
}
func main() {
in, _ := os.Open("11541.in")
defer in.Close()
out, _ := os.Create("11541.out")
defer out.Close()
var line string
var t int
fmt.Fscanf(in, "%d", &t)
for kase := 1; kase <= t; kase++ {
fmt.Fscanf(in, "%s", &line)
fmt.Fprintf(out, "Case %d: %s\n", kase, strings.Join(decode(line), ""))
}
}