-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path824.cpp
More file actions
29 lines (29 loc) · 788 Bytes
/
Copy path824.cpp
File metadata and controls
29 lines (29 loc) · 788 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
class Solution {
public:
string toGoatLatin(string S) {
string ret;
int m = 1, n = S.size();
for (int i = 0; i < n; ++i) {
int j = i + 1;
while (j != n && S[j] != ' ')
++j;
string temp;
char t = tolower(S[i]);
bool vowel = (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u');
if (vowel)
temp += S[i];
temp += S.substr(i + 1, j - i - 1);
if (!vowel)
temp += S[i];
temp += "ma";
for (int k = 0; k < m; ++k)
temp += 'a';
++m;
i = j;
if(i != n)
temp += ' ';
ret += temp;
}
return ret;
}
};