Skip to content

Commit 8e45a06

Browse files
add 824
1 parent 541b4f9 commit 8e45a06

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

src/0824-Goat-Latin/0824.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution
2+
{
3+
public:
4+
string toGoatLatin(string S)
5+
{
6+
unordered_set<char> vowel({'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'});
7+
stringstream in(S);
8+
string res, w;
9+
int i = 0, j;
10+
while (in >> w)
11+
{
12+
res += ' ' + (vowel.count(w[0]) ? w : w.substr(1) + w[0]) + "ma";
13+
res += string(++i, 'a');
14+
}
15+
return res.substr(1);
16+
}
17+
};

src/0824-Goat-Latin/0824.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
func toGoatLatin(S string) string {
2+
vowel := "aeiouAEIOU"
3+
vowels := make(map[rune]int)
4+
for _, c := range vowel {
5+
vowels[c]++
6+
}
7+
tokens := strings.Split(S, " ")
8+
res, i := "", 1
9+
for _, w := range tokens {
10+
res += " "
11+
if _, ok := vowels[rune(w[0])]; ok {
12+
res += w;
13+
} else {
14+
res += w[1:] + string(w[0])
15+
}
16+
res += "ma" + strings.Repeat("a", i)
17+
i++
18+
}
19+
return res[1:]
20+
}

src/0824-Goat-Latin/0824.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public String toGoatLatin(String S) {
3+
Set vowels = new HashSet();
4+
for (char c : "aeiouAEIOU".toCharArray()) vowels.add(c);
5+
String res = "";
6+
String[] tokens = S.split(" ");
7+
int i = 0;
8+
for (String w : tokens) {
9+
res += ' ' + (vowels.contains(w.charAt(0)) ? w : w.substring(1) + w.charAt(0)) + "ma";
10+
res += String.join("", Collections.nCopies(++i, "a"));
11+
};
12+
return res.substring(1);
13+
}
14+
}

src/0824-Goat-Latin/0824.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var toGoatLatin = function(S) {
2+
let vowels = new Set(), vowel = "aeiouAEIOU", res = "";
3+
for (let c of vowel) vowels.add(c);
4+
let tokens = S.split(" "), i = 1;
5+
for (let w of tokens) {
6+
res += " " + (vowels.has(w.charAt(0)) ? w : w.substring(1) + w.charAt(0)) + "ma";
7+
res += Array(++i).join("a");
8+
}
9+
return res.substring(1);
10+
};

src/0824-Goat-Latin/0824.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def toGoatLatin(self, S: str) -> str:
3+
res, vowels = [], set("aeiouAEIOU")
4+
S = S.split(" ")
5+
for i, w in enumerate(S):
6+
if w[0] not in vowels:
7+
w = w[1:] + w[0]
8+
res.append(w + "ma" + (i + 1) * "a")
9+
return " ".join(res)

0 commit comments

Comments
 (0)