一、题目
二、分析
题意:给你一段密码,判断这段密码是否安全,若安全则是
acceptable。
密码必须同时满足下面三个限制条件才是安全密码:
1、必须包含元音字母;
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;
}