-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path11233.go
More file actions
57 lines (50 loc) · 981 Bytes
/
11233.go
File metadata and controls
57 lines (50 loc) · 981 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
46
47
48
49
50
51
52
53
54
55
56
57
// UVa 11233 - Deli Deli
package main
import (
"fmt"
"os"
"strings"
)
var (
irregulars = make(map[string]string)
eses = []string{"o", "s", "ch", "sh", "x"}
vowelsY = []string{"ay", "ey", "iy", "oy", "uy"}
)
func consonantAndY(word string) bool {
for _, vowelY := range vowelsY {
if strings.HasSuffix(word, vowelY) {
return false
}
}
return true
}
func solve(word string) string {
if p, ok := irregulars[word]; ok {
return p
}
if consonantAndY(word) {
return word[:len(word)-1] + "ies"
}
for _, es := range eses {
if strings.HasSuffix(word, es) {
return word + "es"
}
}
return word + "s"
}
func main() {
in, _ := os.Open("11233.in")
defer in.Close()
out, _ := os.Create("11233.out")
defer out.Close()
var l, n int
var w1, w2 string
for fmt.Fscanf(in, "%d%d", &l, &n); l > 0; l-- {
fmt.Fscanf(in, "%s%s", &w1, &w2)
irregulars[w1] = w2
}
for ; n > 0; n-- {
fmt.Fscanf(in, "%s", &w1)
fmt.Fprintln(out, solve(w1))
}
}