HDU——1039 Easier Done Than Said?

题意:对一个字符串s进行处理,有三个条件:第一,该字符串至少含有一个元音;第二,字符串不能含有连续的三个元音或者辅音;第三,字符串不能含相邻的两个字符相等,除了“ee”和“oo”外,如果字符串s满足三个条件,输出"<s>  is acceptable."否则输出”<s>  is not acceptable.

解题思路:该题关键点是判断三个条件:是否含有一个元音,是否含有连续的三个元音或者辅音,是否含有相邻的两个字符相等,可以分别写三个判断函数进行依次判断,详见code。

code:

#include <iostream>
#include <string>
using namespace std;

string vowel;
int isvowel(char s)
{
    if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') return 1;
    else return 0;
}

int judge1(int n)
{
    for(int i = 2; i < n; i++)
    {
        if(isvowel(vowel[i-2]) && isvowel(vowel[i-1]) && isvowel(vowel[i])) return 0;
        if(!isvowel(vowel[i-2]) && !isvowel(vowel[i-1]) && !isvowel(vowel[i])) return 0;
    }
    return 1;
}

int judge2(int n)
{
    for(int i = 0; i < n; i++)
    {
        if(isvowel(vowel[i])) return 1;
    }
    return 0;
}

int judge3(int n)
{
  for(int i = 1; i < n; i++)
  {
      if(vowel[i-1] == vowel[i] && vowel[i] != 'e'&& vowel[i] != 'o') return 0;
  }
  return 1;
}

int main()
{
    while(cin>>vowel && vowel != "end")
    {
        int len = vowel.length();
        if(judge1(len) == 0)
        {
           cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
           continue;
        }
        if(judge2(len) == 0)
        {
           cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
           continue;
        }
        if(judge3(len) == 0)
        {
           cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
           continue;
        }
        cout<<"<"<<vowel<<">"<<" is acceptable."<<endl;
    }
    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值