您的位置:首页 > 大数据 > 人工智能

poj-1575-Easier Done Than Said?

2015-08-04 11:18 465 查看
题目就不都贴上了,贴关键的就OK了

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.

意思就是说输入多组字符串,如果符合三个条件,则密码是可接受的;

具体条件简单翻译下:

1:必须包含一个元音;

2:不能连续包含三个元音或辅音;

3:相邻的位子不能有相同的元音,出了‘o’和’e’;

好了,这是道水题:

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
char a[100];
while(cin>>a)
{
if(strcmp(a,"end")==0)
break;
int flag=0;
int len=strlen(a);
int i;
for( i=0;i<len;i++)
{
if(a[i]!='a'&&a[i]!='e'&&a[i]!='i'&&a[i]!='o'&&a[i]!='u')
continue;
else
break;
}
//cout<<i<<endl;
if(i==len)
{
flag=1;
}
//cout<<flag<<endl;
for(i=0;i<len;i++)
{
if((a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')&&(a[i+1]=='a'||a[i+1]=='e'||a[i+1]=='i'||a[i+1]=='o'||a[i+1]=='u')&&(a[i+2]=='a'||a[i+2]=='e'||a[i+2]=='i'||a[i+2]=='o'||a[i+2]=='u')&&i+2<len)
flag=1;
if((a[i]!='a'&a[i]!='e'&&a[i]!='i'&&a[i]!='o'&&a[i]!='u')&&(a[i+1]!='a'&&a[i+1]!='e'&&a[i+1]!='i'&&a[i+1]!='o'&&a[i+1]!='u')&&(a[i+2]!='a'&&a[i+2]!='e'&&a[i+2]!='i'&&a[i+2]!='o'&&a[i+2]!='u')&&i+2<len)
flag=1;
}
// cout<<flag<<endl;
for(i=0;i<len;i++)
{
if(a[i]==a[i+1]&&a[i]!='o'&&a[i]!='e'&&i+1<len){
flag=1;
break;
}
}
// cout<<flag<<endl;
if(flag)
cout<<"<"<<a<<"> "<<"is not acceptable."<<endl;
else
cout<<"<"<<a<<"> "<<"is acceptable."<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: