hdu 1039 Easier Done Than Said? day24

题目
http://acm.hdu.edu.cn/showproblem.php?pid=1039

总结
我一开始以为他是要我判断是不是元音单词还是辅音单词,总而言之想的很怪,无从下手
查了之后才知道原来就只用符合三个条件就是密码了。
要同时满足三个条件,所以flag最好设置3个。
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’.(不能有两个连续的单词除了‘ee’和‘oo’)
(For the purposes of this problem, the vowels are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’;
all other letters are consonants.)(元音字母:a、e、i、o、u;辅音字母:除了这些其他的所有字母)
Input
The input consists of one or more potential passwords, one per line,
followed by a line containing only the word ‘end’(end是结束的标志) that
signals the end of the file. Each password is at least one and
at most twenty letters long(长度不超过20个单词) and consists only of lowercase letters(仅有小写字母构成).
Output
For each password, output whether or not it is acceptable

AC代码

#include <stdio.h>
#include <string.h>
int main()
{
	int flag1,flag2,flag3,shuchu[25];
	char shuru[25],yuan[]="aeiou";
	//不能这么赋值char yuan[5]={a,e,i,o,u};
	while(scanf("%s",&shuru)==1&&(strcmp(shuru,"end")!=0))//一开始没想到用到这个字符串比较函数 
	{
		memset(shuchu,0,sizeof(shuchu));
		flag1=flag2=flag3=0;
		for(int i=0;i<strlen(shuru);i++)
		{
			for(int j=0;j<5;j++)
			{
				if(shuru[i]==yuan[j])
				{
					shuchu[i]=1;
					flag1=1;
					continue; 
				}
			}
		}
		for(int i=0;i<strlen(shuru);i++) 
		{
			if(shuchu[i]==shuchu[i+1]&&shuchu[i+2]==shuru[i])
			{
				flag2=1;
				break;
			}
		}
		for(int i=0;i<strlen(shuru);i++)
		{
			if(shuru[i]==shuru[i+1]&&(shuru[i]!='e'&&shuru[i]!='o'))//直接判定第一个字母就好了 
			{
				flag3=1;
				break;
			}
		}
		if(flag1==1&&flag2==0&&flag3==0)//要考虑他输入只有两个字母的情况,有的时候没有进循环就直接输出了 
		{
			printf("<%s> is acceptable.\n",shuru);
		} 
		else
		{
			printf("<%s> is not acceptable.\n",shuru);
		} 
	}
	return 0;	
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值