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:

  1. It must contain at least one vowel.
  2. It cannot contain three consecutive vowels or three consecutive consonants.
  3. 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.

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. 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到20之间,包括1和20.需要满足3个条件才是可接受的,否则是不可接受的。条件一:必须含有一个元音字母;条件二:不能有连续三个元音或辅音字母;条件三:不能有连续两个相同字母,连续的oo和ee除外。

解题思路:用三个bool型变量分别表示三个条件是否成立。若字符串中有元音字母,则flag1=true;若没有连续的三个辅音或元音flag2=true;若没有连续两个相同的字母,flag3=true。对了,不能忘记字符串长度为1的情况,此时若为元音,则可以接受。

源代码:

#include<iostream>
#include<string>
using namespace std; bool isVowel(char c)             //判断字符c是否为元音字母,是则返回true 
{
     bool flag=false;
     if(c=='a')flag=true;
     else if(c=='o')flag=true;
     else if(c=='e')flag=true;
     else if(c=='i')flag=true;
     else if(c=='u')flag=true;
     return flag;
} bool isSame(string s)           //判断是否有连续两个相同字母,若没有则返回true 
{
     bool flag=true;
     for(int i=0;i<s.size()-1;++i)
     {
           if(s[i]==s[i+1]&&s[i]!='e'&&s[i]!='o')
           {
                flag=false;
                break;
           }
     }
     return flag;
} int main()
{
    int flag[20];
    string s;
    while(cin>>s&&s!="end")
    {
          bool flag1=false,flag2=false,flag3=true;
          for(int i=0;i<20;++i)                   //用于存储相同类别的字母的长度 
               flag[i]=1;
          
          if(s.size()==1&&isVowel(s[0]))cout<<'<'<<s<<'>'<<" is acceptable."<<endl;      //长度为1的情况 
          else if(s.size()==1&&!isVowel(s[0]))cout<<'<'<<s<<'>'<<" is not acceptable."<<endl;
          
          else if(s.size()>1)                            //长度大于1的情况 
          {
               int flag1=false,flag2=true,flag3=true;    
               if(isVowel(s[0]))flag1=true;
               
               for(int i=1;i<s.size();++i)
               {
                    //若是元音字母,则是flag1=true 
                    if(isVowel(s[i]))flag1=true;
                    //连续两个相同字母 ,则使对应的flag[i]=flag[i-1]+1 
                    if( (isVowel(s[i-1])&&isVowel(s[i])) || (!isVowel(s[i-1])&&!isVowel(s[i])) )flag[i]=++flag[i-1];
                    //若相同类别的字母最大长度大于2,则使flag3=false,并退出循环 
                    if(flag[i]>2){flag3=false;break;}
               }
               flag2=isSame(s);        //判断是否有连续相同的字符 
               if(flag1 && flag2 && flag3)cout<<'<'<<s<<'>'<<" is acceptable."<<endl;
               else cout<<'<'<<s<<'>'<<" is not acceptable."<<endl;
          }
    }
    return 0;


TJU Easier Done than Said?的更多相关文章

  1. HBase官方文档

    HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...

  2. hdu 1039 Easier Done Than Said? 字符串

    Easier Done Than Said?                                                                     Time Limi ...

  3. ural 1356. Something Easier(数论,哥德巴赫猜想)

    1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...

  4. (转)Is attacking machine learning easier than defending it?

    转自:http://www.cleverhans.io/security/privacy/ml/2017/02/15/why-attacking-machine-learning-is-easier- ...

  5. TJU Problem 2857 Digit Sorting

    原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted ...

  6. TJU 2248. Channel Design 最小树形图

    最小树形图,測模版.... 2248.   Channel Design Time Limit: 1.0 Seconds   Memory Limit: 65536K Total Runs: 2199 ...

  7. HDU 1039.Easier Done Than Said?-条件判断字符串

    Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  8. 1658: Easier Done Than Said?

    1658: Easier Done Than Said? Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 15  Solved: 12[Submit][St ...

  9. HDU 1039.Easier Done Than Said?【字符串处理】【8月24】

    Easier Done Than Said? Problem Description Password security is a tricky thing. Users prefer simple ...

随机推荐

  1. CodeForces 738E Subordinates

    排序,构造. 相当于告诉我们一棵树$n$个节点,每个节点在哪一层,至少需要移动多少个节点,才能让这些节点变成一棵树. 按照层次排个序移动一下就可以了,优先选择那些不是$s$但是层次是$0$的节点,如果 ...

  2. Matrix Zigzag Traversal(LintCode)

    Matrix Zigzag Traversal Given a matrix of m x n elements (m rows, ncolumns), return all elements of ...

  3. 使用keras时出现 `pydot` failed to call GraphViz的解决办法

    问题来源于使用了 keras.utils.plot_model,报错内容为: 2018-08-29 08:58:21.937037: I tensorflow/core/platform/cpu_fe ...

  4. RabbitMQ (十二) 消息确认机制 - 发布者确认

    消费者确认解决的问题是确认消息是否被消费者"成功消费". 它有个前提条件,那就是生产者发布的消息已经"成功"发送出去了. 因此还需要一个机制来告诉生产者,你发送 ...

  5. 具有jQuery背景的程序员如何转换为AngularJS思考模式(译)

    最近一直在研究angularjs,最大的感受就是它和之前的jQuery以及基于jQuery的各种库设计理念完全不同,如果不能认识到这点而对于之前做jQuery开发的程序员,去直接学习angularjs ...

  6. 【BZOJ 4572】【SCOI 2016】围棋

    http://www.lydsy.com/JudgeOnline/problem.php?id=4572 轮廓线DP:设\(f(i,j,S,x,y)\). \(S\)表示\((i,1)\)到\((i, ...

  7. Codeforces 500 E. New Year Domino

    \(>Codeforces \space 500 E. New Year Domino<\) 题目大意 : 数轴上有序排列着 \(n\) 块多米诺骨牌, 第 \(i\) 块骨牌坐标为 \( ...

  8. [JSOI2017]原力(分块+map(hash))

    题目描述 一个原力网络可以看成是一个可能存在重边但没有自环的无向图.每条边有一种属性和一个权值.属性可能是R.G.B三种当中的一种,代表这条边上 原力的类型.权值是一个正整数,代表这条边上的原力强度. ...

  9. 【Kruskal+dfs】BZOJ1016- [JSOI2008]最小生成树计数

    [题目大意] 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树. [思路] 拖欠了三个月整(?)的题目,搞出来弄掉了……本年度写的时候姿势最丑 ...

  10. 轻量级的REST中间件

    轻量级的REST中间件 纯净的REST中间件,绝对的轻量级,不需要安装任何三方控件 基于HTTPS.SYS和WEBSOCKET通信,支持海量并发 支持跨越DELPHI6~DELPHI10.2.2的开发 ...