Easier Done Than Said?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16170 Accepted Submission(s): 7692 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. 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. |
代码:
#include<iostream>
#include<cstring>
using namespace std;
char s[25];
int judge(int i)
{
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
return 1;
return 0;
}
int main()
{
while(cin>>s)
{
int n=strlen(s);
if(s[0]=='e'&&s[1]=='n'&&s[2]=='d'&&n==3)
break;
int flag=0;
int i;
for(i=0;i<n;i++)
{
if(judge(i))
break;
}
if(i>=n)
flag=1;
for(i=1;i<n;i++)
{
if(flag)
break;
if(s[i]==s[i-1])
{
if(s[i]=='e'||s[i] == 'o')
continue;
flag=1;
break;
}
}
for(i=2;i<n;i++)
{
if(flag)
break;
if(judge(i)&&judge(i-1)&&judge(i-2))
flag=1;
else if(!judge(i)&&!judge(i-1)&&!judge(i-2))
flag=1;
}
if(!flag)
{
cout<<"<";
for(int i=0;i<n;i++)
cout<<s[i];
cout<<"> is acceptable."<<endl;
}
else
{
cout<<"<";
for(int i=0;i<n;i++)
cout<<s[i];
cout<<"> is not acceptable."<<endl;
}
memset(s,0,sizeof(s));
}
return 0;
}