UVA – 492 – Pig-Latin

#include <iostream>
#include <sstream>
#include <string>
#include <ctype.h>
#include <stdio.h>
using namespace std;
bool isvowel(char c) {
	c = tolower(c);
	return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
void decode(string& s) {
	if (s.size() <= 0 ) return;
	if (!isvowel(s[0])) { s += s[0]; s.erase(0, 1); }
	printf("%say", s.c_str());
	s="";
}
int main() {
	string line, s;
	while (getline(cin, line)) {
		s = "";
		for (size_t i = 0; i < line.size(); ++i) {
			if (isalpha(line[i]))
				s += line[i];
			else {
				decode(s);
				printf("%c", line[i]);
			}
		}
		decode(s);
		printf("\n");
	}
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: