Easier Done than Said?(字符串问题)
来源:互联网 发布:dota2数据网站 编辑:程序博客网 时间:2024/06/10 20:41
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
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.
解析:题意是给一个字符串,判断字符串中是否有元音字母,是否有三个连续的元音或者辅音字母,是否有连续两个相同的字母,排除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;
}
- Easier Done than Said?(字符串问题)
- Easier Done Than Said?(字符串)
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- Easier Done Than Said?
- [HDOJ 1039] Easier Done Than Said? (基础,字符串) .
- HDU-1039-Easier Done Than Said?(简单字符串处理)
- hdu 1039 Easier Done Than Said?(字符串模拟)
- HDU 1039-Easier Done Than Said?(字符串)
- HDU 1039 Easier Done Than Said? (字符串)
- 超链接调用 JavaScript 函数
- 新特性
- service
- java class类 详解~~~
- 能用的Myeclipse Svn中用户名和密码修改
- Easier Done than Said?(字符串问题)
- UTMS 信令培训(9)
- struts2 <s:property/>标签的使用--输出时间格式转换
- 程序员的美:极致与疯狂
- Android音频系统之音频基础
- android 点滴
- Spring配置文件中加载数据源几种方式
- 本地无法启动MySQL服务,出现1067错误提示
- Windows PowerShell ISE