zoukankan      html  css  js  c++  java
  • 字符串 HDU 1039

    规则:

    1.必须至少包含一个元音字母。a e i o u

    2.不能包含三个连续元音或者连续辅音字母。

    3.不能包含两个连续字母,除了'ee'和'oo'。

    PS:字母个数(1<= N <=20).

    #define _CRT_SECURE_NO_DEPRECATE
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int is_vowel(char strIn)
    {
        if(strIn == 'a' || strIn == 'e' ||strIn == 'i' || strIn == 'o' || strIn == 'u')
            return 1;
        else
            return 0;
    }
    
    void main()
    {
        while(1)
        {
            char strIn[21] = {''};
            char strTemp[21] = {''}; //字符缓存,用于判断是否连续出现相同字符
            char temp;
            int count = 0;  //统计连续相同字母个数
            int count2 = 0; //统计连续的元音或者辅音字母个数
            int vowelFlag = 0; //是否元音的标志位
            int lastIsVowel = 0; //上一个字母是否是元音的标志位 0 不是 1 是
            int sign = 0; //是否含有元音标志位
            int resultFalg = 1;
            int len; //保存输入的字符串的长度
            gets(strIn);
            len = (int)strlen(strIn);
            //先判断是否是结束查询标志
            if(strcmp(strIn, "end") == 0)
                return;
            temp = strIn[0];
            count = 1;
            count2 = 1;
            vowelFlag = is_vowel(strIn[0]);
            lastIsVowel = is_vowel(strIn[0]);
            //查找是否包含元音字母,如果遇到连续3个元音字母,辅音字母或者连续2个除了'ee''oo'之外的相同字母,则判断为不可接受,并退出循环
            for(int i = 0; i < len; i++)
            {
                if(sign == 0)
                    sign = is_vowel(strIn[i]);
                //如果出现相同的字母
                if(i > 0 && temp == strIn[i])
                {
                    count++;
                    if(count == 2)
                    {
                        if(temp != 'e' && temp != 'o')
                        {
                            resultFalg = 0; //不可接收,跳出循环
                            break;
                        }
                    }
                }
                //如果出现三个连续元音或连续三个辅音
                if(i > 0)
                {
                    vowelFlag = is_vowel(strIn[i]);
                    if(vowelFlag == lastIsVowel)
                    {
                        count2++;
                        if(count2 >= 3)
                        {
                            resultFalg = 0; //不可接收,跳出循环
                            break;
                        }
                    }
                    else
                    {
                        count2 = 1;
                        lastIsVowel = vowelFlag;
                    }
    
                }
                temp = strIn[i];
                count = 1;
    
            }
    
            if(sign == 1 && resultFalg != 0)
            {
                printf("<%s> is acceptable.", strIn );
                printf("
    ");
            }
            else
            {
                printf("<%s> is not acceptable.", strIn );
                printf("
    ");
            }
        }
    }

  • 相关阅读:
    登入界面的创建
    什么是IO流 以及文件输入输出
    java 的面向对象
    Mac 终端命令大全
    jQuery 的属性
    商城管理系统
    Java IO学习第二天部分详解
    Java IO学习第一天部分详解
    用JAVA描述一个车与修车厂两个事物
    JAVA基础(数组)数组排序和查找数组中是否还有某一个数
  • 原文地址:https://www.cnblogs.com/mrethan/p/4640709.html
Copyright © 2011-2022 走看看