杭电 HDU 1039 Easier Done Than Said?

Easier Done Than Said?Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9231Accepted Submission(s): 4503

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

atvptouibontreszoggaxwiinqeephouctuhend

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.

Source

Mid-Central USA 2000

题意很好理解,仔细思考一下想到了应该将条件划分,,就像数字电路 对应三个条件的输入状态 映射输出状态 下面代码中 只有0 1 0 的条件下 才输出1(acceptable);

接下来 问题转化为如何设计去 对三个条件加以判断的问题

#include<iostream>#include<string>#include<string.h>using namespace std;char cnt[100];//cnt数组用0和1两种状态标志str中原音和辅音情况void ls(string &str){for(int m=0;m<str.size();m++)if(str[m]=='a'||str[m]=='e'||str[m]=='i'||str[m]=='o'||str[m]=='u')cnt[m]=1;}int main(){string str;int flag1,flag2,flag3;while(cin>>str,str!="end"){flag1=flag2=flag3=0;memset(cnt,0,sizeof(cnt));ls(str);if((str.size()==1))//接下来根据flag1 2 3 的状态分别判断三个条件的情况flag1=cnt[0]==1?0:1;else {for(int i=0;i<(str.size()-2);i++)//str。size()-2的值不是-1 是正数在str只有一个字母的时候 要单独判断一个元素的情况{if((cnt[i]==cnt[i+1])&&(cnt[i+1]==cnt[i+2])){flag1=1;break;}}}for(int j=0;j<str.size();j++)if(cnt[j]==1)flag2=1;for(int k=0;k<str.size()-1;k++)if(str[k]==str[k+1])if((str[k]=='e')||(str[k]=='o'))continue;else{flag3=1;break;}if(((flag1==0)&&(flag3==0))&&(flag2==1))//如果flag三个条件同时满足则……cout<<"<"<<str<<">"<<" is acceptable."<<endl;elsecout<<"<"<<str<<">"<<" is not acceptable."<<endl;}return 0;}

为你的难过而快乐的是敌人,

杭电 HDU 1039 Easier Done Than Said?

相关文章:

你感兴趣的文章:

标签云: