原题链接:824. 山羊拉丁文
solution:模拟题
class Solution {
public:
string toGoatLatin(string sentence) {
int n = sentence.length();
string res = ""; //定义返回值
for(int i = 0,k = 0;i < n;i++){
int j = i;
while(j < n && sentence[j] != ' ') j++;
k++; //索引+1
if(tolower(sentence[i]) == 'a' || tolower(sentence[i]) == 'e' || tolower(sentence[i]) == 'i' || tolower(sentence[i]) == 'o' || tolower(sentence[i]) == 'u'){
res += sentence.substr(i, j - i);
res += "ma";
for(int i = 0;i < k;i++)
res += "a";
if(j != n) res += " ";
}
else{
res += sentence.substr(i + 1,j - i - 1);
res += sentence[i];
res += "ma";
for(int i = 0;i < k;i++)
res += "a";
if(j != n) res += " ";
}
i = j;
}
return res;
}
};