题目链接:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1186

题意比较好懂,就是编的时候有点小纠结,分清情况讨论就行!!

代码:

#include <stdio.h>
#include <string.h>
char word[100];//存字串
int count1,count2,count3;//分别用于三个条件的计数
void f1()//检查第一个条件
{
int n,i;
count1=0;
n=strlen(word);
for(i=0;i<n;i++)
{
if(word[i]==’a’||word[i]==’e’||word[i]==’i’||word[i]==’o’||word[i]==’u’)
{
count1=1;
return ;
}
}
}
void f2()//检查第二个条件
{
int n,i;
count2=1;
n=strlen(word);
for(i=1;i<n;i++)
{
if((word[i]==’a’||word[i]==’e’||word[i]==’i’||word[i]==’o’||word[i]==’u’)
&&(word[i-1]==’a’||word[i-1]==’e’||word[i-1]==’i’||word[i-1]==’o’||word[i-1]==’u’))
{
count2++;
continue;
}
if((word[i]!=’a’&&word[i]!=’e’&&word[i]!=’i’&&word[i]!=’o’&&word[i]!=’u’)
&&(word[i-1]!=’a’&&word[i-1]!=’e’&&word[i-1]!=’i’&&word[i-1]!=’o’&&word[i-1]!=’u’))
{
count2++;
continue;
}
if(count2>=3)
return;
else
count2=1;

}
}
void f3()//检查第三个条件
{
int n,i;
count3=0;
n=strlen(word);
for(i=1;i<n;i++)
{
if(word[i]==word[i-1]&&(word[i]!=’e’&&word[i]!=’o’))
{
count3=1;
return ;
}
}
}
int main()
{

memset(word,0,sizeof(word));
while(gets(word),strcmp(word,”end”))
{
if(strlen(word)==1)
{
printf(“<%s> is acceptable.\n”,word);
continue;
}
count1=count2=count3=0;
f1();
if(count1==0)
{
printf(“<%s> is not acceptable.\n”,word);
continue;
}
else
{
f2();
if(count2>=3)
{
printf(“<%s> is not acceptable.\n”,word);
continue;
}
else
{
f3();
if(count3==1)
{
printf(“<%s> is not acceptable.\n”,word);
continue;
}
}
}
printf(“<%s> is acceptable.\n”,word);
}
return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation