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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
bool isVowel(char c)
{
c = tolower(c);
if(c == 'a') return true;
if(c == 'i') return true;
if(c == 'u') return true;
if(c == 'e') return true;
if(c == 'o') return true;
return false;
}
bool trackVowelWord(string message, int i, int &i_first)
{
for(i; i >= 1; i--)
{
if(isalpha(message[i]) && !isalpha(message[i-1]))
{
i_first = i;
return isVowel(message[i]);
}
}
if(isalpha(message[i]))
{
i_first = i;
return isVowel(message[i]);
}
i_first = i;
return false;
}
void equipPigLatin(string &message, int &i)
{
int i_first;
bool isVowel = trackVowelWord(message, i, i_first);
if(isVowel)
{
i++;
message.insert(message.begin() + i, 'y');
message.insert(message.begin() + i, 'a');
message.insert(message.begin() + i, 'y');
i += 3;
}
else
{
char c = message[i_first];
message.erase(message.begin() + i_first);
message.insert(message.begin() + i, c);
i++;
message.insert(message.begin() + i, 'y');
message.insert(message.begin() + i, 'a');
i += 2;
}
}
int main()
{
int i;
string message;
getline(cin, message);
for(i = 0; i < message.length() - 1; i++)
{
if(isalpha(message[i]) && !isalpha(message[i + 1]))
{
equipPigLatin(message, i);
}
}
i = message.length() - 1;
if(isalpha(message[i-1]))
{
equipPigLatin(message, i);
}
cout << message;
return 0;
}
| |