-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoatLatin.cpp
38 lines (32 loc) · 874 Bytes
/
goatLatin.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
class Solution {
public:
bool isVowel(char c) {
c = tolower(c);
return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u');
}
string toGoatLatin(string S) {
string ans="", curr="", suff = "a";
string cons="";
int len = S.length(), firstLet=1;
for(int i=0; i<len; i++) {
if (firstLet == 1) {
firstLet = 0;
if(!isVowel(S[i])) {
cons = S[i];
continue;
}
}
if(S[i] == ' ') {
ans += curr + cons + "ma" + suff + " ";
cons = "";
curr = "";
suff += "a";
firstLet = 1;
continue;
}
curr += S[i];
}
ans += curr + cons + "ma" + suff;
return ans;
}
};