题解报告:hdu 1039 Easier Done Than Said?
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039
Problem Description
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
Output
Sample Input
Sample Output
问题描述
密码安全性是一件棘手的事情。用户更喜欢易于记忆的简单密码(比如好友),但这样的密码通常不安全。有些网站使用随机计算机生成的密码(如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?的更多相关文章
- hdu 1039 Easier Done Than Said? 字符串
Easier Done Than Said? Time Limi ...
- HDU 1039.Easier Done Than Said?-条件判断字符串
Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1039.Easier Done Than Said?【字符串处理】【8月24】
Easier Done Than Said? Problem Description Password security is a tricky thing. Users prefer simple ...
- HDOJ/HDU 1039 Easier Done Than Said?(字符串处理~)
Problem Description Password security is a tricky thing. Users prefer simple passwords that are easy ...
- HDU 1039 -Easier Done Than Said?
水水的 #include <iostream> #include <cstring> using namespace std; ]; bool flag; int vol,v2 ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- 题解报告: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 ...
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...
随机推荐
- c++多线程编程:常见面试题
题目:子线程循环 10 次,接着主线程循环 100 次,接着又回到子线程循环 10 次,接着再回到主线程又循环 100 次,如此循环50次,试写出代码 子线程与主线程必有一个满足条件(flag == ...
- 在XX公司工作第二天,维护已有代码
根据<C++ More Exception>所述的规则: Rule #1: Never write using-directives in header files. Rule #2: N ...
- Linux登录自动切换root账户与历史命令优化
1:当我们Linux系统优化完成,会使用oldboy用户远程连接CRT登录,每次连接都需要使用sudo su - 或者su - 输入密码登录,请问如何在CRT连接的时候自动的切换到root账户,(提示 ...
- 浅谈 ZipArchive 类
Microsoft .NET Framework 4.5 新增了 ZipArchive 类 Microsoft Windows 8 Consumer Preview 操作系统已经内置了 Microso ...
- web 开发之js---页面缓存, jsp 缓存, html 缓存, ajax缓存,解决方法
有关页面缓存问题.这个问题上网找了好多.但发觉各种解决方法,都彼此分离,没有一篇统一的解决方法,本人近日,也遇到了页面缓存的问题,根据网上各页面缓存的解答,做了一个总结. 1.服务器端缓存的问题, 防 ...
- Intellig Idea2017新建Web项目(tu'wen)
1.新建新工程项目 2.选择Java 和JDK版本 3.下一步Next(默认不勾选) 4.设置Project Name ,点击More Setting图标可以折叠.展开 然后Finish 我们可以看 ...
- struts2的(S2-045,CVE-2017-5638)漏洞测试笔记
网站用的是struts2 的2.5.0版本 测试时参考的网站是http://www.myhack58.com/Article/html/3/62/2017/84026.htm 主要步骤就是用Burp ...
- jetty9 web app的部署
jetty9将web app和web app的context配置文件都放在${JETTY_HOME}/webapps下面. 例如,如果有一个myapp.war,首先将其放入${JETTY_HOME}/ ...
- 总结文件操作函数(二)-C语言
格式化读写: #include <stdio.h> int printf(const char *format, ...); //相当于fprintf( ...
- 剑指Offer面试题11(Java版):数值的整数次方
题目:实现函数double Power(double base,int exponent),求base的exponent次方.不得使用库函数,同一时候不须要考虑大数问题 1.自以为非常easy的解法: ...