-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11220.go
59 lines (53 loc) · 1 KB
/
11220.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 11220 - Decoding the message.
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func solve(lines []string) []string {
var words []string
for _, line := range lines {
var tmp string
var word strings.Builder
for idx, r := 0, strings.NewReader(line); ; {
if _, err := fmt.Fscanf(r, "%s", &tmp); err != nil {
break
}
if len(tmp) > idx {
word.WriteByte(tmp[idx])
idx++
}
}
words = append(words, word.String())
}
return words
}
func main() {
in, _ := os.Open("11220.in")
defer in.Close()
out, _ := os.Create("11220.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var t int
var line string
s.Scan()
fmt.Sscanf(s.Text(), "%d", &t)
s.Scan()
for kase := 1; kase <= t; kase++ {
var lines []string
for s.Scan() {
if line = s.Text(); line == "" {
break
}
lines = append(lines, line)
}
if kase > 1 {
fmt.Fprintln(out)
}
fmt.Fprintf(out, "Case #%d:\n", kase)
fmt.Fprintln(out, strings.Join(solve(lines), "\n"))
}
}