zoukankan      html  css  js  c++  java
  • HDU 1039.Easier Done Than Said?【字符串处理】【8月24】

    Easier Done Than Said?

    Problem Description
    Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable" passwords that are relatively secure but still easy to remember.

    FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:

    It must contain at least one vowel.

    It cannot contain three consecutive vowels or three consecutive consonants.

    It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.

    (For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.
     

    Input
    The input consists of one or more potential passwords, one per line, followed by a line containing only the word 'end' that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.
     

    Output
    For each password, output whether or not it is acceptable, using the precise format shown in the example.
     

    Sample Input
    a tv ptoui bontres zoggax wiinq eep houctuh end
     

    Sample Output
    <a> is acceptable. <tv> is not acceptable. <ptoui> is not acceptable. <bontres> is not acceptable. <zoggax> is not acceptable. <wiinq> is not acceptable. <eep> is acceptable. <houctuh> is acceptable.

    1:有元音字母

    2:不能三个连续元音或辅音

    3:不能连续两个同样的字母,除非ee或oo

    直接推断。代码例如以下:

    #include<cstdio>
    #include<cstring>
    int yuanfu[27]={0};
    bool yuan(char s[]){//推断有无元音字字母
        for(int i=0;i<strlen(s);i++)
        if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
            return true;
        return false;
    }
    bool sanlian(char s[]){//推断有无三个连续的元音或辅音字母
        if(strlen(s)<3) return true;
        for(int i=0;i<strlen(s)-2;i++)
        if(yuanfu[s[i]-'a']==yuanfu[s[i+1]-'a']&&yuanfu[s[i+1]-'a']==yuanfu[s[i+2]-'a'])
            return false;
        return true;
    }
    bool erlian(char s[]){//推断有无两个连续同样非ee或oo字母
        if(strlen(s)<2) return true;
        for(int i=0;i<strlen(s)-1;i++)
        if(s[i]==s[i+1]&&!(s[i]=='e'||s[i]=='o'))
            return false;
        return true;
    }
    int main(){
        char s[110];
        yuanfu[0]=yuanfu[4]=yuanfu[8]=yuanfu[14]=yuanfu[20]=1;
        while(scanf("%s",s)!=EOF&&strcmp(s,"end")){
            if(!yuan(s)) printf("<%s> is not acceptable.
    ",s);
            else if(!sanlian(s)) printf("<%s> is not acceptable.
    ",s);
            else if(!erlian(s)) printf("<%s> is not acceptable.
    ",s);
            else printf("<%s> is acceptable.
    ",s);
        }
        return 0;
    }
    


  • 相关阅读:
    Single Image Haze Removal Using Dark Channel Prior翻译
    android的单元测试
    HTML&JS笔记(1)
    动手学Javascript(1)——PopStar
    Cocos2d-x教程第(11)讲-利用遮罩(蒙版)CCLayerColor制作新手引导界面(上)
    硬币翻转倍数递增试算
    java泛型接口详解
    1352
    大话设计模式之——简单工厂模式
    iOS自适应行高方法及问题
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7027967.html
Copyright © 2011-2022 走看看