PKU 1575 Easier Done Than Said?

  • 時間制限が緩いので条件を丁寧に書けば通る
static int type[256];

bool check(const string& s) {
	vector<int> types;
	for (string::const_iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it) {
		types.push_back(type[*it]);
	}

	if (find(types.begin(), types.end(), 1) == types.end()) {
		return false;
	}

	vector<int> threeConsonants(3, 0);
	vector<int> threeVowels(3, 1);

	if (search(types.begin(), types.end(), threeConsonants.begin(), threeConsonants.end()) != types.end()) {
		return false;
	}

	if (search(types.begin(), types.end(), threeVowels.begin(), threeVowels.end()) != types.end()) {
		return false;
	}

	for (char c = 'a'; c <= 'z'; ++c) {
		if (c == 'e' || c == 'o') {
			continue;
		}
		const string target(2, c);

		if (s.find(target) != string::npos) {
			return false;
		}
	}

	return true;
}

int main() {
	memset(type, 0, sizeof(type));
	type['a'] = 1;
	type['e'] = 1;
	type['i'] = 1;
	type['o'] = 1;
	type['u'] = 1;

	string s;
	while (getline(cin, s) && s != "end") {
		if (check(s)) {
			printf("<%s> is acceptable.\n", s.c_str());
		} else {
			printf("<%s> is not acceptable.\n", s.c_str());
		}
	}
}