[恢]hdu 1039

2011-12-20 16:28:14

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1039

题意:判断一个字符串是否能被接受。要满足:1.含有元音字母。2.不存在3个连续的元音字母或辅音字母。 3.不存在连续两个相同的字母,除非是'ee'或'oo'。

代码:

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


char str[1010] ;


int isvowels (char ch)
{
if (ch == 'a' || ch == 'e' ||
ch == 'i' || ch == 'o' || ch == 'u') return 1 ;
return 0 ;
}


int t1(char str[])
{
int i ;
for (i = 0 ;str[i] ;i++)
if (isvowels(str[i])) return 1 ;
return 0 ;
}


int t2(char str[])
{
int i ;
for (i = 2 ; str[i] ; i++)
{
if (isvowels(str[i]) && isvowels(str[i-1]) && isvowels(str[i-2]))
return 0 ;
if (!isvowels(str[i]) && !isvowels(str[i-1]) && !isvowels(str[i-2]))
return 0 ;
}
return 1 ;
}


int t3(char str[])
{
int i ;
for (i = 1 ; str[i] ; i++)
if (str[i] == str[i-1] && str[i] != 'e'&&str[i] != 'o') return 0 ;
return 1 ;
}


int test(char str[])
{
if (t1(str) == 0) return 0 ;
if (t2(str) == 0) return 0 ;
if (t3(str) == 0) return 0 ;
return 1 ;
}


int main ()
{
while (gets(str))
{
if (strcmp(str, "end") == 0) break ;
printf ("<%s> is %sacceptable.\n", str, test(str)?"":"not ") ;
}
return 0 ;
}



posted @ 2012-01-06 23:16  Seraph2012  阅读(202)  评论(0编辑  收藏  举报