luoheng
10/11/2019 - 2:48 PM

toGoatLatin


import "strings"

func word(s string) string {
    switch s[0] {
    case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U':
        s += "ma"
    default:
        s = s[1:] + string(s[0]) + "ma"
    }
    return s
}

func toGoatLatin(S string) string {
    str := strings.Split(S, " ")
    for i := 0; i < len(str); i++ {
        str[i] = word(str[i]) + strings.Repeat("a", i+1)
    }
    return strings.Join(str, " ")
}