一、题目
二、分析
题意:给你一段密码,判断这段密码是否安全,若安全则是
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;
}
本文详细阐述了如何通过编程实现安全密码的检测算法,包括元音字母、连续字符及重复字母的判断,确保密码强度符合特定标准。
1644

被折叠的 条评论
为什么被折叠?



