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.
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. 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.
解析:题意是给一个字符串,判断字符串中是否有元音字母,是否有三个连续的元音或者辅音字母,是否有连续两个相同的字母,排除e和o。
水题一枚;
#include"stdio.h"
#include"string.h"
char s[10000];
int j1(int i) //to determine whether there are vowels
{
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
return 1;
else
return 0;
}
int j2(int i) //to determine whether there are contain three consecutive vowels
{
if((s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')&&
(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u')&&
(s[i+2]=='a'||s[i+2]=='e'||s[i+2]=='i'||s[i+2]=='o'||s[i+2]=='u'))
return 1;
else
return 0;
}
int j3(int i) //to determine whether there are three consecutive consonants
{
if(!(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')&&
!(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u')&&
!(s[i+2]=='a'||s[i+2]=='e'||s[i+2]=='i'||s[i+2]=='o'||s[i+2]=='u'))
return 1;
else
return 0;
}
int j4(int i) //to determine there are whether two consecutive ocurrences of the same letters
{
if(s[i]==s[i+1]&&s[i]!='e'&&s[i]!='o')
return 1;
else
return 0;
}
int main()
{
int i,j,len,flag1,flag2,flag3;
while(gets(s)&&strcmp(s,"end"))
{
flag1=1;
flag2=flag3=0;
len=strlen(s);
if(len==1)
{
if(j1(0))
printf("<%s> is acceptable.\n",s);
else
printf("<%s> is not acceptable.\n",s);
continue;
}
if(len==2)
{
if((j1(0)||j1(1))&&!j4(0))
printf("<%s> is acceptable.\n",s);
else
printf("<%s> is not acceptable.\n",s);
continue;
}
for(i=0;i<len-3;i++)
{
if(j1(i))
flag1=0;
if(j3(i)||j2(i)) //contain three consecutive
flag2=1;
if(j4(i)) //contain two consecutive
flag3=1;
}
if(j1(len-3)||j1(len-2)||j1(len-1))
flag1=0;
if(j2(len-3)||j3(len-3))
flag2=1;
if(j4(len-3)||j4(len-2))
flag3=1;
if(flag1==1||flag2==1||flag3==1)
printf("<%s> is not acceptable.\n",s);
else
printf("<%s> is acceptable.\n",s);
}
return 0;
}