poj3371 Flesch Reading Ease

Flesch Reading Ease
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2237 Accepted: 695

Description

Flesch Reading Ease, a readability test named after its deviser Rudolf Flesch, is among most ubiquitously used readability tests, which are principally employed for assessment of the difficulty to understand a reading passage written in English. The Flesch Reading Ease score of a passage relies solely on three statistics, namely the total numbers of sentences, words and syllables, of the passage. Specifically, the score is defined by the following formula:


As can be inferred from the above formula, a passage with a high Flesch Reading Ease score tends to favor shorter sentences and words, which is in compliance with commonsense in spite of partial accuracy. (Think of, for instance, the word "television". Long as it may seem, it is indeed one of the first words that any individual who studies English learns.) A related Wikipedia entry on Flesch Reading Ease [1] suggests that passages scoring 90~100 are comprehensible for an average American 5th grader, and 8th and 9th graders possess the ability to follow passages with a score in the range of 60~70, whereas passages not exceeding 30 in the score are best suitable for college graduates. The text of this problem, all sections taken into account, scores roughly 50 as per the calculation of Google Documents.

Despite the simplicity in its ideas, several aspects of its definition remains vague for any real-world implementation of Flesch Reading Ease. For the sake of precision and uniformity, the following restrictions adapted from [2] are adopted for this problem, to which you are to write a solution that effectively computes the Flesch Reading Ease score of a given passage of English text.

  1. Periods, explanation points, colons and semicolons serve as sentence delimiters.
  2. Each group of continuous non-blank characters with beginning and ending punctuation removed counts as a word.
  3. Each vowel (one of a, e, i, o, u and y) in a word is considered one syllable subject to that
    1. -es, -ed and -e (except -le) endings are ignored,
    2. words of three letters or shorter count as single syllables,
    3. consecutive vowels count as one syllable.
References
  1. Wikipedia contributors. Flesch-Kincaid Readability Test. Wikipedia, The Free Encyclopedia. August 30, 2007, 01:57 UTC. Available at: http://en.wikipedia.org/w/index.php?title=Flesch-Kincaid_Readability_Test&oldid=154509512. Accessed September 5, 2007.
  2. Talburt, J. 1985. The Flesch index: An easily programmable readability analysis algorithm. In Proceedings of the 4th Annual international Conference on Systems Documentation. SIGDOC '85. ACM Press, New York, NY, 114-122.

Input

The input contains a passage in English whose Flesch Reading Ease score is to be computed. Only letters of the English alphabet (both lowercase and uppercase), common punctuation marks (periods, question and exclamation marks, colons, semicolons as well as commas, quotation marks, hyphens and apostrophes), and spaces appear in the passage. The passage is of indefinite length and possibly occupies multiple lines. Additionally, it is guaranteed to be correct in punctuation. 

Output

Output the Flesch Reading Ease score of the given passage rounded to two digits beyond decimal point. 

Sample Input

Flesch Reading Ease, a readability test named after its deviser Rudolf Flesch,
is among most ubiquitously used readability tests, which are principally
employed for assessment of the difficulty to understand a reading passage
written in English. The Flesch Reading Ease score of a passage relies solely
on three statistics, namely the total numbers of sentences, words and
syllables, of the passage.

Sample Output

26.09

不得不说,模拟题面都好长啊,长啊,啊,让我这个英语渣情何以堪QAQ。

题意:给你一段英文文字,然后让你判断一下它的单词个数word,句子个数sentence,以及音节数syllable。

然后带入上面的那个公式中,计算出其值。

思路:模拟嘛,

1.找到单词的分隔点就单词个数加一。

2.找到句子的分隔点就句子个数加一,单词个数加一。

最重要的就是音节数,因为它有自己的规则啊,说实话真的是好坑。题目上完全看不出来,题太难读..........wa的不行了QAQ只好抱小优大腿qwq

注:下面的分隔符不包括 括号(),所有分隔符均为 英式标点符号

 

标记单词分隔符: 逗号(,) 和 空格( )

句子分隔符:句号(.) 问号(?) 冒号(:) 分号(;) 感叹号(!)

 

不存在上述标点符号以外的符号!!!所有符号只占一个字符的位置!!

什么 省略号、引号、连字符、问号+叹号、斜杠 等等符号统统不存在!!


关于音节的处理,它有自己的条件:

1.当单词长度<=3的时候,此时音节数强制为1。

2.当单词长度大于3时,每出现一个元音字母音节数加一。但是下面两种情况(3.4)除外。

3.连续的元音字母其总音节为1。

4.当元音字母为e结尾的时候是只有以le为结尾的单词音节加1,其余的不加。如果以ed或者es结尾的这个e不加。

注意:

1.里面存在大写字母,句子开头都是大写的,这段文字是标准的英文片段。当然大写只有可能存在一个单词的开头。

剩下的就看代码啦。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int word=0,sentence=0,syllable=0;
//判断是否是元音
bool isvowel(char a)
{
    if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='y')return 1;
    if(a=='A'||a=='E'||a=='I'||a=='O'||a=='U'||a=='Y')return 1;
    return 0;
}
//判断是否为单词分隔符,注意这里空格并没有记录进来(最后一个字符是字母就是代表间隔空格啦)
bool isword(char a)
{
    if(a==',')return 1;
    return 0;
}
//判断是否为句子分隔符
bool issentance(char a)
{
    if(a=='.'||a=='?'||a==':'||a==';'||a=='!')return 1;
    return 0;
}

char s[110];
int main()
{
    int i;
    int wordlen,flag,syl;
    //wordlen表示当前单词的长度,flag用来标记上一个字母是不是元音,syl用来记录当前单词的音节数。
    {
        wordlen=0;
        flag=0;
        syl=0;
        for(i=0; s[i]; ++i)
        {
            if(isalpha(s[i]))//如果是字母
            {
                wordlen++;
                if(wordlen<=3)//如果当前单词长度≤3
                {
                    if(!isalpha(s[i+1]))//单词长度确定≤3
                    {
                        syllable++;
                        syllable-=syl;//之前记录的syl都不算
                        syl=0;
                        continue;
                    }
                }
                if(isvowel(s[i]))//如果是元音
                {
                    if(s[i]=='e')
                    {
                        if(!isalpha(s[i+1]))//e结尾
                        {
                            if(s[i-1]=='l')//le结尾
                            {
                                syllable++;
                                syl++;
                                continue;
                            }
                            else continue;
                        }
                        else if((s[i+1]=='d'||s[i+1]=='s')&&!isalpha(s[i+2]))continue;//ed,es结尾
                    }
                    if(!flag)//前一个不是元音
                    {
                        flag=1;
                        syllable++;
                        syl++;
                        continue;
                    }
                    else continue;//否则不计
                }
                else flag=0;//如果当前字母不是元音
            }
            else if(isword(s[i]))//如果是单词分隔符
            {
                flag=wordlen=syl=0;//当前单词处理完,清零
                word++;
            }
            else if(issentance(s[i]))//如果是句子分隔符
            {
                flag=wordlen=syl=0;
                word++;
                sentence++;
            }

        }
        if(isalpha(s[i-1]))word++;//如果是间隔空格
    }
    printf("%.2f\n",206.835-1.015*word/sentence-84.6*syllable/word);
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值