forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoat Latin.cpp
36 lines (36 loc) · 905 Bytes
/
Goat Latin.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
class Solution {
public:
string toGoatLatin(string sentence) {
sentence += ' ';
vector<string> Words;
string TEMP, SOL, A = "a";
for (int i = 0; i < sentence.size(); ++i)
{
if (sentence[i] == ' ')
{
Words.push_back(TEMP);
TEMP = "";
}
else
TEMP += sentence[i];
}
for (string V : Words)
{
char TMP = tolower(V[0]);
if (TMP == 'a' || TMP == 'e' || TMP == 'i' || TMP == 'o' || TMP == 'u')
V += "ma";
else
{
TMP = V[0];
V.erase(0, 1);
V += TMP;
V += "ma";
}
V += A;
A += 'a';
SOL += V + ' ';
}
SOL.erase(SOL.size() - 1, 1);
return SOL;
}
};