加载中...

POJ 3371 - Flesch Reading Ease


0x00 POJ 原题

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:

206.835 - 1.015 * words / sentences - 84.6 * syllables / words.

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 90100 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 6070, 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

Source

POJ Monthly–2007.09.09, frkstyc

0x10 题目概述

给出一篇规范的文章,求其 句子数、单词数 和 音节数

把这 3 个值代入题目给出的公式,输出其结果,保留 2 位小数。

“规范”即文章没有错误的标点符号,字母在适当的位置有大小写。

0x20 解题思路

模拟法做,我做了整整 5 天的 BT 题,,就是被标点符号害的!!!

别听信网上谗言,我个人总结出这题的标点符号只有 6 个!!!

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

  • 标记单词分隔符: 逗号(,) 和 空格()
  • 句子分隔符:句号(.) 问号(?) 冒号(:) 分号(;) 感叹号(!)

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

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

知道这个,后面的就好做了:

  • 每出现一个单词分隔符,单词数+1
  • 每出现一个句子分隔符,句子数+1

注意: 由于用 while(cin>>msg) 输入文章,因此是按 空字符 把文章分开若干片段,直到出现 EOF 时才结束输入,因此 msg 中的单词分隔符不会出现空格,只要当 msg 最后一个字符为字母时,就说明此时的单词分隔符为空格。

音节数是最难处理的,其规律如下:

  • (1)当单词总长度 <=3 时,音节数无条件+1
  • (2)当单词总长度 >3 时,单词中每出现一个元音字母(a、e、i、o、u、y),音节数+1,但是连续的元音字母只按 1 个音节计算,且当单词后缀为-es、-ed 和-e 时,后缀的元音字母 e 不列为音节数计算。但是后缀-le 例外,要计算音节数。

注意:

  • (1) 元音字母要判断 12 个,6 个小写,6 个大写。
  • (2) 输入的文章每个字符只能扫描一次,若重复扫描会超时。

0x30 AC 源码

//Memory Time 
//244K   0MS 

#include<iostream>
#include<iomanip>
using namespace std;

int word=0;     //单词数
int sentance=0; //句子数
int syllable=0; //音标数

bool isalpha(char ch)  //检查字符ch是否为字母
{
    if(ch>='A' && ch <='Z')
        return true;
    if(ch>='a' && ch <='z')
        return true;
    return false;
}

bool isvowel(char ch)  //检查字符ch是否为元音字母
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='y')
        return true;
    if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' || ch=='Y')
        return true;
    return false;
}

bool isword(char ch)  //检查字符ch是否为单词分隔符
{
    if(ch==',')
        return true;
    return false;
}

bool issentance(char ch)  //检查字符ch是否为句子分隔符
{
    if(ch=='.' || ch=='?'  || ch==':' || ch==';' || ch=='!')
        return true;
    return false;
}

int main(void)
{
    char msg[1000];

    while(cin>>msg)   //以空格为标记,截取文章片段
    {    
        int wordlen=0;
        bool flag_frevowel=false;   //当当前字符为元音时,检查前一字符是否为元音的标记
        int syl=0;  //假设当前单词长度>3时,记录音节数的变化量。若单词实际长度<=3,则syllable-syl
        int i;

        for(i=0;msg[i];i++)
        {
            if(isalpha(msg[i]))   //当前字符为 字母
            {
                wordlen++;  //当前所处理的单词的已知长度 (已知长度<=实际长度)

                if(wordlen<=3)  //当 已知长度<=3 时
                {
                    if(!isalpha(msg[i+1]))   //检查单词实际长度是否<=3
                    {
                        syllable++;     //当实际长度<=3时,syllable无条件+1
                        syllable-=syl;   //实际音节数调整,单词实际长度<=3,则syllable减去 "假设单词长度>3时" 音节数的变化量syl
                        syl=0;
                        continue;
                    }
                }

                if(isvowel(msg[i]))    //当前字母为 元音字母
                {
                    if(msg[i]=='e')
                    {
                        if(!isalpha(msg[i+1]) && msg[i-1]=='l')  //-le
                        {
                            syllable++;
                            syl++;      //由于不知道单词的实际长度,因此总音节数syllable与音节数变化量syl同时递增
                            continue;
                        }
                        else if(!isalpha(msg[i+1]))  // -e
                            continue;
                        else if((msg[i+1]=='d' || msg[i+1]=='s') && !isalpha(msg[i+2]))  // -ed  -es
                            continue;
                    }

                    /*处理连续或单个元音*/

                    if(!flag_frevowel)   //当前字母为元音,但前一字符不是元音
                    {
                        flag_frevowel=true;
                        syllable++;
                        syl++;
                        continue;
                    }
                    else     //当前字母为元音,但前一字母也是元音,即出现连续元音,syllable不计数
                        continue;
                }

                flag_frevowel=false;   //当前字母不是元音
            }
            else if(isword(msg[i]))   //当前字符为 单词分隔符
            {
                flag_frevowel=false;
                wordlen=0;  //当前单词操作已结束,长度清零,计算下一单词
                syl=0;
                word++;
            }
            else if(issentance(msg[i]))   //当前字符为 句子分隔符
            {
                flag_frevowel=false;
                wordlen=0;  //当前单词操作已结束,长度清零,计算下一单词
                word++;
                syl=0;
                sentance++;
            }

        }

        if(isalpha(msg[i-1]))     //当前文章片段最后一个字符为 字母
            word++;
    }

    cout<<fixed<<setprecision(2)<<206.835-1.015*(double)word/(double)sentance-84.6*(double)syllable/(double)word<<endl;
    return 0;
}

相关资料


文章作者: EXP
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 EXP !
赏
  目录