Wednesday, June 10, 2015

UVa 576 - Haiku Review

// UVa 576 - Haiku Review
#include <iostream>
#include <string>
using namespace std;

bool vow(char ch) {
	return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y');
}

int main() {
	string line;
	while (getline(cin, line) && (line.length() != 5 || line[0] != 'e' || line[2] != 'o' || line[4] != 'i')) {
		int slash1 = line.find('/');
		string verse[4];
		verse[1] = line.substr(0, slash1);
		int slash2 = line.find('/', slash1 + 1);
		verse[2] = line.substr(slash1 + 1, slash2 - slash1 - 1);
		verse[3] = line.substr(slash2 + 1, line.length() - slash2 - 1);

		char sol = 'Y';
		for (int j = 1; j <= 3; j++) {
			bool last_vow = false;
			int c = 0;
			for (int i = 0; i < verse[j].length(); i++) {
				if (vow(verse[j][i])) {
					last_vow = true;
				} else if (last_vow) {
					c++;
					last_vow = false;
				}
			}
			if (last_vow)
				c++;
			if (j == 1 && c != 5) {
				sol = '1';
				break;
			} else if (j == 2 && c != 7) {
				sol = '2';
				break;
			} else if (j == 3 && c != 5) {
				sol = '3';
				break;
			}
		}
		cout << sol << endl;
	}
	return 0;
}

No comments:

Post a Comment