-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathac824.go
More file actions
44 lines (39 loc) · 686 Bytes
/
Copy pathac824.go
File metadata and controls
44 lines (39 loc) · 686 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
package problem824
import (
"strings"
"bytes"
)
func toGoatLatin(S string) string {
words := strings.Fields(S)
var buffer bytes.Buffer
vowels := map[string]int{
"a": 1,
"e": 1,
"i": 1,
"o": 1,
"u": 1,
"A": 1,
"E": 1,
"I": 1,
"O": 1,
"U": 1,
}
for i := 0; i < len(words); i++ {
first := string(words[i][0])
if vowels[first] == 1 {
buffer.WriteString(words[i])
buffer.WriteString("ma")
} else {
buffer.WriteString(string(words[i][1:]))
buffer.WriteString(first)
buffer.WriteString("ma")
}
for j := 0; j <= i; j++ {
buffer.WriteString("a")
}
if i != len(words)-1 {
buffer.WriteString(" ")
}
}
return buffer.String()
}