HDU-1039-Easier Done Than Said?(简单字符串处理)


题目传送门: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;
} 





                                                   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值