-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
43 lines (43 loc) · 1.31 KB
/
solution.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
class Solution {
public:
string toGoatLatin(string S) {
string result;
int i = 0;
int count = 0;
bool vowel = false;
string word;
while(i<S.size()){
if(S[i]==' '){
i++;
continue;
}else if(S[i]=='a'||S[i]=='A'||S[i]=='e'||S[i]=='E'||S[i]=='i'
||S[i]=='I'||S[i]=='o'||S[i]=='O'||S[i]=='u'||S[i]=='U'){
int j=0;
for(;i+j<S.size();j++)
if(S[i+j] == ' ')
break;
word = S.substr(i, j);
result.append(word);
result.append("ma");
result.append(count+1, 'a');
result.append(1, ' ');
count += 1;
i += j;
}else{
int j=0;
for(;i+j<S.size();j++)
if(S[i+j] == ' ')
break;
word = S.substr(i+1, j-1);
result.append(word);
result.append(1,S[i]);
result.append("ma");
result.append(count+1, 'a');
result.append(1, ' ');
count += 1;
i += j;
}
}
return result.substr(0,result.size()-1);
}
};