题目链接: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. CSS浮动通俗讲解

    首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...

  2. Java编程50题

    [程序1]    题目:古典问题:有一对兔子.从出生后第3个月起每一个月都生一对兔子,小兔子长到第三个月后每一个月又生一对兔子,假如兔子都不死.问每一个月的兔子总数为多少?    //这是一个菲波拉契 ...

  3. rand和srand的用法(转载)

    首先我们要对rand&srand有个总体的看法:srand初始化随机种子,rand产生随机数,下面将详细说明. rand(产生随机数)表头文件: #include<stdlib.h> ...

  4. BZOJ 1005 明明的烦恼 Prufer序列+组合数学+高精度

    题目大意:给定一棵n个节点的树的节点的度数.当中一些度数无限制,求能够生成多少种树 Prufer序列 把一棵树进行下面操作: 1.找到编号最小的叶节点.删除这个节点,然后与这个叶节点相连的点计入序列 ...

  5. hdu 3255 Farming(扫描线)

    题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...

  6. 一个很小的C++写的MVC的例子

    #include<iostream> #include<vector> //get namespace related stuff using std::cin; using ...

  7. BZOJ 3550 ONTAK2010 Vacation 单纯形

    题目大意:给定一个长度为3n的区间.要求选一些数,且随意一段长度为n的区间内最多选k个数.求选择数的和的最大值 单纯形直接搞 注意一个数仅仅能被选一次 因此要加上xi<=1这个约束条件 不明确3 ...

  8. mysql命令行爱好者必备工具mycli

    mycli MyCLI is a command line interface for MySQL, MariaDB, and Percona with auto-completion and syn ...

  9. java语法基础(一)

    这个是自己前两年做java视频教程时候的课件.感兴趣的同学可以参考下. 这里是纯粹的语法行总结. editplus的使用 选择项目目录 打开editplus 左侧目录导航栏 可以打开盘符,文件夹 可以 ...

  10. C#使用 webBrowser 控件总结

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...