HDU 1039 - Check Words

Check Words:

It should be filtered by:

-->> It must contain at least one vowel.
-->> It cannot contain three consecutive vowels or three consecutive consonants.
-->> It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.


Set a flag, and check three times by three functions and figure out whether the words is corresponse with the given filter


<a> is acceptable.
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.
***********************************************

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char a[25];
int iPut;

bool fIsVowel(char key);
void fCheck(char a[]);
void fCheckB(char a[]);
void fCheckC(char a[]);

int main() {
	while(true) {
		cin >> a;
		if(!strcmp(a, "end"))
			return 0;
		iPut = 1; //Default as pass;

		fCheck(a);
		if(iPut)
			fCheckB(a);
		if(iPut)
			fCheckC(a);
		if(iPut)
			cout << "<" << a << "> is acceptable." << endl;
		else
			cout << "<" << a << "> is not acceptable." << endl;
	}
	return 0;
}
void fCheck(char a[]) {
	for(int i = 0; i < strlen(a); i++) {
		if(fIsVowel(a[i])) {
			return;
		}
	}
	//if not vowel is found, set output is false;
	iPut = 0;
}
void fCheckB(char a[]) {
	int iFlagA = 0;
	int iFlagB = 0;
	for(int i = 0; i < strlen(a); i++) {
		if(fIsVowel(a[i])) {
			iFlagA++;
			iFlagB = 0;
		}
		else {
			iFlagB++;
			iFlagA = 0;
		}
		if(iFlagA == 3 || iFlagB == 3) {
			iPut = 0;
			return;
		}
	}
}
void fCheckC(char a[]) {
	char cPrevious = a[0];
	for(int i = 1; i < strlen(a); i++) {
		if(a[i] == cPrevious && a[i] != 'e' && a[i] != 'o') {
			iPut = 0;
			return;
		}
		cPrevious = a[i];
	}
}

bool fIsVowel(char key) {
	return key == 'a' || key == 'e' || key == 'i' || key == 'o' || key == 'u';
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值