UVA492:

Pig-Latin

#include <iostream>
#include <string>

using namespace std;

int main(){
	
	string s;

	// string h="hello world"; 
	// string v="aeiou"; 
	
	// cout << *find_first_of(h.begin(), h.end(), v.begin(), v.end()) << endl;
	while(getline(cin, s)){
		string result = "";
		
		for(int c = 0; c < s.length(); c++){
			int i = 0;
			string word = "";
			while(true){
				bool isLetter = (s[i + c] >= 'a' && s[i + c] <= 'z') 
					|| (s[i + c] >= 'A' && s[i + c] <= 'Z');

				if(isLetter){
					word += s[i + c];
					i++;

				} else {
					c += i;
					break;
				}
			}

			// cout << "Word is: " << word << endl;

			if(!word.empty()){

				bool isVowel = word[0] == 'A' || word[0] == 'E' || 
						  		word[0] == 'I' || word[0] == 'O' ||
						  		word[0] == 'U' || word[0] == 'a' ||
							  	word[0] == 'e' || word[0] == 'i' ||
								word[0] == 'o' || word[0] == 'u'; 

				if(isVowel){
					result += word + "ay";
				} else {
					result += word.substr(1) + word[0] + "ay";

				}

			}
			
			result += s[c];

		}

		cout << result << endl;

	}

	return 0; 

}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel