HDU 1039 Easier Done Than Said?

一、题目

点击打开题目

二、分析

题意:给你一段密码,判断这段密码是否安全,若安全则是 acceptable。
密码必须同时满足下面三个限制条件才是安全密码:
1、必须包含元音字母;
2、不能包含连续的三个元音或辅音字母;
3、除了ee和oo外,任何两个连续字母如果相同,密码就不安全。

三、代码

#include <stdio.h>
#include <string.h>


int main()
{
	char s[21];
	int i, csct_vow,csct_cons;//定义连续的元音字母和辅音字母计数变量
	int same_tag, vow_tag, cons_tag, len;

	while (~(scanf("%s", s)))
	{
		len = strlen(s);
		if (len < 1 || len > 20)
			break;

		/* compare string with 'end', if equal then break */
		if (!strcmp(s, "end"))
			break;

		csct_vow = csct_cons = same_tag = vow_tag = 0;

		/* check if string contain two consecutive occurrences of the same letter */
		for (i = 0; i < len-1; ++i)
		{
			if (s[i] == s[i+1] && (s[i] != 'e' && s[i] != 'o'))
			{
				same_tag = 1;
				break;
			}
		}


		csct_cons = cons_tag = 0;
		/* Is there a vowel letter in the string at least?*/
		for (i = 0; i < len; ++i)
		{
			if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
			{
				/* mark consecutive vowel letter */
				++csct_vow;
				csct_cons= 0;

				if (vow_tag < csct_vow)
					vow_tag = csct_vow;
			} 
			else
			{
				/* mark consecutive consonant letter */
				++csct_cons;
				csct_vow = 0;
				if (cons_tag < csct_cons)
					cons_tag = csct_cons;
			}
		}
		if (same_tag || vow_tag > 2 || cons_tag > 2 || !vow_tag)
			printf("<%s> is not acceptable.\n", s);
		else
			printf("<%s> is acceptable.\n", s);

	}
	return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值