Goat Latin
<-E 824> Goat Latin
class Solution {
public:
string toGoatLatin(string S) {
unordered_set<char> vowel({'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'});
istringstream iss(S);
string res, w;
int i = 0;
while (iss >> w) {
res += " ";
if (vowel.count(w[0]) != 0) {
res += w;
} else {
res += w.substr(1) + w[0];
}
res += "ma";
for (int j = 0; j <= i; j++) {
res += "a";
}
i++;
}
return res.substr(1);
}
};