hdu1039

点击打开链接

大笑大笑

判断该字符串是否是acceptable的,满足三个条件

1,必须包含一个元音;

2,不能包含三个连续的元音or三个连续的辅音;

3,不能包含两个连续相同的字母,除了ee或者oo;


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


char s[]={'a','e','i','o','u'};
bool is_yuan(char x)//判断字母是否是元音字母
{
    for(int i=0;i<5;i++)
        if(x==s[i])
            return true;
    return false;
}
char pwd[30];
int main()
{
    while( scanf("%s",pwd)==1&& strcmp(pwd,"end")!=0 )//读入一个密码
    {
        bool ok1=false,ok2=true,ok3=true;//ok1,ok2,ok3分别代表3个条件是否满足,true表满足
        int len = strlen(pwd);
        for(int i=0;i<len;i++)//是否有至少一个元音字母
        {
            if(is_yuan( pwd[i] ))
            {
                ok1=true;
                break;
            }
        }
        if(ok1)
        {
            for(int i=0;i<len-2;i++)//不能连续3个元音或连续3个辅音在一起
            {
                if( is_yuan(pwd[i])&&is_yuan(pwd[i+1])&&is_yuan(pwd[i+2]))
                {
                    ok2=false;
                    break;
                }
                else if( !is_yuan(pwd[i])&& !is_yuan(pwd[i+1])&& !is_yuan(pwd[i+2]))
                {
                    ok2=false;
                    break;
                }
            }
        }
        if(ok1&&ok2)
        {
            for(int i=0;i<len-1;i++)//不能两个相同字母(除ee,oo)在一起
            {
               if(pwd[i]==pwd[i+1]&&pwd[i]!='e'&&pwd[i]!='o')
                {
                    ok3=false;
                    break;
                }
            }
        }
        printf("<%s> is",pwd);
       if(ok1&&ok2&&ok3)printf(" acceptable.\n");
        else printf(" not acceptable.\n");
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值