#include <stdio.h>
#include <string.h>
#define judgesentence (s[len-1]=='.'||s[len-1]=='?'||s[len-1]==':'||s[len-1]==';'||s[len-1]=='!')
#define judgevowel (s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='Y')
int main()
{
char s[110];
int w=0,se=0,sy=0;
while(~scanf("%s",s))
{
if(strcmp(s,"")==0)
continue;
int len=strlen(s);
w++;//每个标点符号输完后都有空格,所以每次s,word++;
if(judgesentence)
se++;//判断句子
if((s[len-1]>='a'&&s[len-1]<='z')||(s[len-1]>='A'&&s[len-1]<='Z'))//单词长度小于3的算作一个音节
{
if(len<=3)
{
sy++;
continue;
}
}
//这里本来没有if语句的,后来,看了一个测试数据
//"A. Ole drei end dead fucked. AES. DES. Maerlyn's. Gute. TTOLE."
//再试试 Tom's doctors'
else if(s[len-1]==','||s[len-1]=='.'||s[len-1]==':'||s[len-1]==';'||s[len-1]=='?'||s[len-1]=='!')
{
s[len-1]='\0';
if(len<=4)
{
sy++;
continue;
}
}
len=strlen(s);
int i=0;
while(i<len)
{
if(judgevowel)
{
sy++;
while(i<len&&judgevowel)
{
i++;
}
}
else i++;
}
//后缀为-ed,-es的,得考虑它前面有没有连着的元音字母,因为连续的字母算一个,ttttaaed
if((s[len-2]=='e'||s[len-2]=='E')&&(s[len-1]=='d'||s[len-1]=='D'||s[len-1]=='S'||s[len-1]=='s')
&&s[len-3]!='a'&&s[len-3]!='e'&&s[len-3]!='i'&&s[len-3]!='o'&&s[len-3]!='u'
&&s[len-3]!='y'
&&s[len-3]!='A'&&s[len-3]!='E'&&s[len-3]!='I'&&s[len-3]!='O'&&s[len-3]!='U'
&&s[len-3]!='Y')
{
sy--;
}
// 后缀为-e的,这里试试这些数据thre three threeee thrae
if((s[len-2]!='l'&&s[len-2]!='L'&&s[len-2]!='e'&&s[len-2]!='E'&&s[len-2]!='a'&&s[len-2]!='A'&&s[len-2]!='i'&&s[len-2]!='I'&&s[len-2]!='o'&&s[len-2]!='O'&&s[len-2]!='u'&&s[len-2]!='U'&&s[len-2]!='y'&&s[len-2]!='Y')&&(s[len-1]=='e'||s[len-1]=='E'))
sy--;
}
double ans=206.835-1.015*w/se-84.6*sy/w;
printf("%.2f\n",ans);
}
【POJ 3371】Flesch Reading Ease
最新推荐文章于 2019-03-31 02:18:50 发布