题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1039
题意:
合格的字符串需要满足三个条件。
(1)至少一个元音;
(2)不能有3个连续的元音或辅音;
(3)不能有连续相同的字母,除非是 ‘e' 或 'o';
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
using namespace std;
#define N 1000005
char s[N];
int main()
{
while(scanf("%s",s),strcmp(s,"end")){ //end 结束
int len=strlen(s);
bool flag1=0,flag=0; //flag1 表示是否出现过元音,flag 表示是否有不符合条件2、3的情况
int a=0,b=0; // a 表示连续的元音, b 表示连续的辅音
for(int i=0;i<len;i++){
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' ||s[i]=='u'){
flag1 = 1;
a++;
b=0;
}else b++,a=0;
if(a==3 || b==3){
flag = 1;
break;
}
if(i!=0 && s[i]!='e'&&s[i]!='o' && s[i]==s[i-1]){
flag = 1;
break;
}
}
if(flag || !flag1){
printf("<%s> is not acceptable.\n",s);
}else printf("<%s> is acceptable.\n",s);
}
return 0;
}