Goat Latin LeetCode solution in C++

1
class Solution {
2
public:
3
string toGoatLatin(string sentence) {
4
sentence += ' ';
5
vector<string> Words;
6
string TEMP, SOL, A = "a";
7
for (int i = 0; i < sentence.size(); ++i) {
8
if (sentence[i] == ' ') {
9
Words.push_back(TEMP);
10
TEMP = "";
11
} else
12
TEMP += sentence[i];
13
}
14
for (string V : Words) {
15
char TMP = tolower(V[0]);
16
if (TMP == 'a' || TMP == 'e' || TMP == 'i' || TMP == 'o' || TMP == 'u')
17
V += "ma";
18
else {
19
TMP = V[0];
20
V.erase(0, 1);
21
V += TMP;
22
V += "ma";
23
}
24
V += A;
25
A += 'a';
26
SOL += V + ' ';
27
}
28
SOL.erase(SOL.size() - 1, 1);
29
return SOL;
30
}
31
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0