-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path824.cpp
More file actions
25 lines (25 loc) · 755 Bytes
/
824.cpp
File metadata and controls
25 lines (25 loc) · 755 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
class Solution {
public:
bool isVowel(char c) {
if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') return true;
return false;
}
string toGoatLatin(string sentence) {
string res;
int index = 0;
string token;
stringstream ss(sentence);
while (getline(ss, token, ' ')) {
if (isVowel(token[0])) {
res += (token + "ma" + string(index + 1, 'a'));
}
else {
res += (token.substr(1) + token[0] + "ma" + string(index + 1, 'a'));
}
res.push_back(' ');
index++;
}
res.pop_back();
return res;
}
};