-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLC_824_GoatLatin.cpp
43 lines (38 loc) · 929 Bytes
/
LC_824_GoatLatin.cpp
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
/*
https://leetcode.com/problems/goat-latin/
824. Goat Latin
*/
class Solution {
public:
string toGoatLatin(string sentence) {
string ans;
unordered_map<char,bool> vow = {
{'a', true},
{'e', true},
{'i', true},
{'o', true},
{'u', true},
{'A', true},
{'E', true},
{'I', true},
{'O', true},
{'U', true}
};
int cnt_a = 1;
stringstream ss(sentence);
string buff;
while(ss>>buff)
{
if(vow.find(buff[0]) != vow.end())
{
ans+= buff+"ma" + string(cnt_a++, 'a')+ ' ';
}
else
{
ans += buff.substr(1) + buff[0] + "ma" + string(cnt_a++, 'a')+ ' ';
}
}
ans.pop_back();
return ans;
}
};