-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path10115.go
More file actions
45 lines (39 loc) · 748 Bytes
/
10115.go
File metadata and controls
45 lines (39 loc) · 748 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
45
// UVa 10115 - Automatic Editing
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func solve(text string, rules [][2]string) string {
for _, rule := range rules {
for strings.Contains(text, rule[0]) {
text = strings.Replace(text, rule[0], rule[1], 1)
}
}
return text
}
func main() {
in, _ := os.Open("10115.in")
defer in.Close()
out, _ := os.Create("10115.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var r int
for s.Scan() {
if fmt.Sscanf(s.Text(), "%d", &r); r == 0 {
break
}
rules := make([][2]string, r)
for i := range rules {
s.Scan()
s1 := s.Text()
s.Scan()
rules[i] = [2]string{s1, s.Text()}
}
s.Scan()
fmt.Fprintln(out, solve(s.Text(), rules))
}
}