zoukankan      html  css  js  c++  java
  • 题解报告:hdu 1039 Easier Done Than Said?

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039

    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.

    问题描述

    密码安全性是一件棘手的事情。用户更喜欢易于记忆的简单密码(比如好友),但这样的密码通常不安全。有些网站使用随机计算机生成的密码(如xvtpzyo),但用户很难记住它们,有时会将它们写在粘在他们计算机上的记事上。一个可能的解决方案是生成相对安全但仍易于记忆的“可发音”密码。

    FnordCom正在开发这样的密码生成器。您在质量控制部门工作,测试发生器并确保密码可接受是您的工作。为了让人接受,密码必须符合以下三条规则:

    它必须至少包含一个元音。

    它不能包含三个连续的元音或三个连续的辅音。

    它不能包含两个连续出现的相同字母,除了'ee'或'oo'。

    (就这个问题而言,元音是'a','e','i','o'和'u';所有其他字母都是辅音。)请注意,这些规则并不完美。有许多不可接受的常见/可发音词汇。  

    输入

    输入由一个或多个潜在密码组成,每行一个,后面跟着一行只包含文字结束的单词'end'。每个密码至少有一个,最多只有二十个字母,并且只包含小写字母。  

    输出

     对于每个密码,使用示例中显示的精确格式输出是否可接受。

    解题思路:规则已经描述得很清楚了,主要是用f数组处理字符串中的字母,便于写if判断语句,然后就照着判断条件便可逐一写下来,写代码注意单一出口,简化代码。

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<string>
     7 #define LL long long
     8 #define PI acos(-1.0)
     9 using namespace std;
    10 char t[5]={'a','e','i','o','u'};
    11 bool isT(char a)//先扫一遍看看有没有元音字母,有的话直接返回真
    12 {
    13     for(int i=0;i<5;i++)
    14         if(a==t[i])return true;
    15     return false;
    16 }
    17 int main()
    18 {
    19     int len;//表示字符串的长度
    20     char a[20]={0};
    21     bool f[20],g,h;//f数组是对字母进行标记
    22     while(cin>>a,strcmp(a,"end")){
    23         len=strlen(a);
    24         memset(f,false,sizeof(f));//全部初始化为false
    25         for(int i=0;i<len;i++)//标记元音
    26             if(isT(a[i]))f[i]=true;//是元音则为true
    27         g=true,h=false;//g来判断条件,而h是用来标记至少有一个元音字母这个条件
    28         for(int i=0;i<len;i++){
    29             if(f[i])h=true;//标记一下是否有元音字母
    30             if(i>0&&a[i]==a[i-1]&&a[i]!='e'&&a[i]!='o'){g=false;break;}//标记连续相等的两个除了是e和o的
    31             if(i>1&&f[i]&&f[i-1]&&f[i-2]){g=false;break;}//标记连续三个是元音的
    32             if(i>1&&!f[i]&&!f[i-1]&&!f[i-2]){g=false;break;}//标记连续三个是辅音的
    33         }
    34         if(!h)g=false;//没有元音字母就置g为假,便于下一出口统一操作(单一出口)
    35         if(g)cout<<'<'<<a<<'>'<<" is acceptable."<<endl;
    36         else cout<<'<'<<a<<'>'<<" is not acceptable."<<endl;
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    HDU1536_SNim_求sg值
    HDU1851_A Simple Game_求sg
    POJ1067_取石子游戏_威佐夫博弈
    HDU1848_Fibonacci again and again_经典的求sg
    POJ2425 && HDU1524_ A Chess Game_树形博弈
    .GB级数据库分区实现高性能
    数据库锁
    热烈庆祝“mysql 集群数据库架构成功”
    linux mysql注意事项
    SQL Server 数据库做读写分离
  • 原文地址:https://www.cnblogs.com/acgoto/p/8635010.html
Copyright © 2011-2022 走看看