/*
题目:给你一个小写字符串,判断是否安全,安全规则如下:
1.包含元音字母;
2.相邻3个元素不能都是元音或辅音;
3.连续2个字母相同之能是o或e。
*/
# include <stdio.h>
# include <string.h>
int judge1(char c) //判断字符是不是元音
{
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
int main(void)
{
char str[20];
while((scanf("%s", str) != EOF) && (strcmp(str, "end")))
{
int flag = 0,i = 0;
getchar(); //吸收回车符。
for(i = 0; i < strlen(str); i++)
if (judge1(str[i]))
flag = 1;
for(i = 2; i < strlen(str); i++)
{
if(judge1(str[i-2]) && judge1(str[i-1]) && judge1(str[i]))//判断全是元音
flag = 0;
if(!judge1(str[i-2]) && !judge1(str[i-1]) && !judge1(str[i]))//判断全是辅音
flag = 0;
}
for(i = 1; i < strlen(str); i++)
{
if(str[i-1] == str[i] && str[i] != 'o' && str[i] != 'e')
flag = 0;
}
if(flag) printf("<%s> is acceptable.\n",str);
else printf("<%s> is not acceptable.\n",str);
}
return 0;
}
HDU 1039 Easier Done Than Said
最新推荐文章于 2021-03-07 16:41:10 发布