题目链接: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 ;
}

最新文章

  1. 用css改变默认的checkbox样式
  2. js实现点击修改按钮之后单元格变成可编辑状态
  3. iOS 1 到 iOS 10 ,我都快老了
  4. javascript获取url信息的常见方法
  5. bzoj 1791 DP
  6. Ecshop实现注册页面手机号唯一的验证
  7. Windows下查看端口被程序占用的方法
  8. Unix/Linux笔记全集
  9. spring+springmvc+mybatis整合框架搭建
  10. Operating system hdu 2835 OPT
  11. 浅谈C语言 extern 指针与数组
  12. [再寄小读者之数学篇](2014-05-28 Ladyzhenskaya 不等式)
  13. vue实现pc端上拉加载功能,不兼容移动端
  14. zabbix server+agent+proxy搭建性能监控平台
  15. SSAS 笔记
  16. SQL Server分区键列必须是主键一部分
  17. abp 依赖注入声明
  18. 使用WampServer搭建本地PHP环境,绑定域名,配置伪静态
  19. unity3D使用C#遍历场景内所有元素进行操作
  20. 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)

热门文章

  1. Client使用c#和odp.net连接server oracle
  2. VC++ VS2010 error LNK1123 转换到 COFF 期间失败 怎么办
  3. window.location.hashs属性介绍
  4. 添加 XML内Rows数据
  5. #Virtual hosts #Include conf/extra/httpd-vhosts.conf 开启就不能启动apache
  6. 分享:APK高级保护方法解析(三)
  7. HDU1251 统计难题 【trie树】
  8. bean的scope属性
  9. 浏览器同部署了https的服务器交互的过程
  10. HTML5你必须知道的28个新特性