-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path11192.go
More file actions
44 lines (38 loc) · 785 Bytes
/
11192.go
File metadata and controls
44 lines (38 loc) · 785 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
44
// UVa 11192 - Group Reverse
package main
import (
"fmt"
"os"
"strings"
)
func reverse(tokens []string) []string {
reversed := make([]string, len(tokens))
for i, token := range tokens {
for j := range token {
reversed[i] = string(token[j]) + reversed[i]
}
}
return reversed
}
func split(line string, n int) []string {
length := len(line) / n
tokens := make([]string, n)
for i := range tokens {
tokens[i] = line[i*length : (i+1)*length]
}
return tokens
}
func main() {
in, _ := os.Open("11192.in")
defer in.Close()
out, _ := os.Create("11192.out")
defer out.Close()
var n int
var line string
for {
if _, err := fmt.Fscanf(in, "%d%s", &n, &line); err != nil || n == 0 {
break
}
fmt.Fprintln(out, strings.Join(reverse(split(line, n)), ""))
}
}