题目链接: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代码:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#define LL long long
#define PI acos(-1.0)
using namespace std;
char t[]={'a','e','i','o','u'};
bool isT(char a)//先扫一遍看看有没有元音字母,有的话直接返回真
{
for(int i=;i<;i++)
if(a==t[i])return true;
return false;
}
int main()
{
int len;//表示字符串的长度
char a[]={};
bool f[],g,h;//f数组是对字母进行标记
while(cin>>a,strcmp(a,"end")){
len=strlen(a);
memset(f,false,sizeof(f));//全部初始化为false
for(int i=;i<len;i++)//标记元音
if(isT(a[i]))f[i]=true;//是元音则为true
g=true,h=false;//g来判断条件,而h是用来标记至少有一个元音字母这个条件
for(int i=;i<len;i++){
if(f[i])h=true;//标记一下是否有元音字母
if(i>&&a[i]==a[i-]&&a[i]!='e'&&a[i]!='o'){g=false;break;}//标记连续相等的两个除了是e和o的
if(i>&&f[i]&&f[i-]&&f[i-]){g=false;break;}//标记连续三个是元音的
if(i>&&!f[i]&&!f[i-]&&!f[i-]){g=false;break;}//标记连续三个是辅音的
}
if(!h)g=false;//没有元音字母就置g为假,便于下一出口统一操作(单一出口)
if(g)cout<<'<'<<a<<'>'<<" is acceptable."<<endl;
else cout<<'<'<<a<<'>'<<" is not acceptable."<<endl;
}
return ;
}

题解报告:hdu 1039 Easier Done Than Said?的更多相关文章

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

    Easier Done Than Said?                                                                     Time Limi ...

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

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

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

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

  4. HDOJ/HDU 1039 Easier Done Than Said?(字符串处理~)

    Problem Description Password security is a tricky thing. Users prefer simple passwords that are easy ...

  5. HDU 1039 -Easier Done Than Said?

    水水的 #include <iostream> #include <cstring> using namespace std; ]; bool flag; int vol,v2 ...

  6. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  7. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  8. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  9. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

随机推荐

  1. JAVA学习(一):Java介绍及其平台、开发环境的配置与搭建

    Java介绍及其平台.开发环境的配置与搭建 1.Java的介绍 Java是一种面向对象的编程语言,具有跨平台.可移植.分布式.简单.可扩展等诸多特性.Java能够进行桌面应用.Web应用.分布式系统及 ...

  2. elasticsarch5.4集群安装

    越来越多的企业已经采用ELK解决方案来对其公司产生的日志进行分析,笔者最近着手在生产环境部署自己的ELK stack,本文介绍ELK中elasticsearch5.2集群的实现. 一.环境准备 1.系 ...

  3. CentOS 7下安装Logstash ELK Stack 日志管理系统(上)

    介绍 The Elastic Stack - 它不是一个软件,而是Elasticsearch,Logstash,Kibana 开源软件的集合,对外是作为一个日志管理系统的开源方案.它可以从任何来源,任 ...

  4. Policy-based design设计模式

    书在4年前看过.今天重温一下: 一直觉得这是最好的设计模式,大牛Andrei Alexandrescu 专门写了书,可见他的重要性 http://en.wikipedia.org/wiki/Polic ...

  5. CMMI 2,3,4,5级涉及的过程域(PA)介绍

      CMMI中的PA即Process Area的缩写,中文称为过程域.简单的说就是做好一个事情需要的某一个方面,对于软件开发来说,就是做好软件开发需要的某一个方面. CMMI2.3级共有18个过程域( ...

  6. ZrcListView

    https://github.com/zarics/ZrcListView

  7. Entity Framework工具POCO Code First Generator的使用(参考链接:https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator)

    在使用Entity Framework过程中,有时需要借助工具生成Code First的代码,而Entity Framework Reverse POCO Code First Generator是一 ...

  8. Delphi汉字简繁体转换代码(分为D7和D2010版本)

    //delphi 7 Delphi汉字简繁体转换代码unit ChineseCharactersConvert; interface uses   Classes, Windows; type   T ...

  9. Cg入门23: Fragment shader – UV动画(序列帧)

    让动画从1-9循环播放此纹理 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkF ...

  10. POJ - 1986 Distance Queries(离线Tarjan算法)

    1.一颗树中,给出a,b,求最近的距离.(我没考虑不联通的情况,即不是一颗树的情况) 2.用最近公共祖先来求, 记下根结点到任意一点的距离dis[],这样ans = dis[u] + dis[v] - ...