poj-3371-Flesch Reading Ease

来源:互联网 发布:java string length() 编辑:程序博客网 时间:2024/06/18 17:40

Flesch Reading Ease
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2293 Accepted: 722

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 principallyemployed for assessment of the difficulty to understand a reading passagewritten in English. The Flesch Reading Ease score of a passage relies solelyon three statistics, namely the total numbers of sentences, words andsyllables, of the passage.

Sample Output

26.09

Source

POJ Monthly--2007.09.09, frkstyc


不得不说英语对于我造成了极大的困扰,MD这么长的英文,我是醉醉的,半天看的一知半解。

题意:

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

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


解题思路:
由于所有的输入符合英语文章的书写标准,所以每个输入的字符串只有两种形式
1.纯的一个单词    word
2.单词加一个结尾的符号    word,
大概就是上述意思。

所以每次输入一个字符串,单词数只管加一;
并且字符分割符如果存在一定在wordlen-1的位置,所以判断字符串的最后一个字符是否为句子的分隔符就可以了,如果是句子加一,
最麻烦的是音节数的统计,他的规则大致如下:

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


不多说上代码:


#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <iomanip>using namespace std;int words = 0;int sentences = 0;int syllables = 0;//是否为元音字符bool isvoewl(char a){if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')return true;if(a == 'A' || a == 'E' || a == 'I' || a == 'O' || a == 'U' || a == 'Y')return true;return false;}//是否为句子的分隔符bool issentance(char a){if(a == '.' || a == '?' || a == ':' || a == ';' || a == '!')return true;return false;}//是否为单词bool isalpha(char a){if(a >= 'a' && a <= 'z')return true;if(a >= 'A' && a <= 'Z')return true;return false;}int main(){char str[1000];while(cin>>str){words++;int wordlen = strlen(str);//如果输入的字符串最后一个为句子的分隔符,句子数加一;if(issentance(str[wordlen-1]))sentences++;//单词长度小于等于3,音节数加一;if((wordlen <= 3) || (wordlen == 4 && !isalpha(str[wordlen-1]))){syllables++;continue;}bool flag_frevowel=false;for(int i = 0; i < wordlen; i++){if(isvoewl(str[i])){if(str[i] == 'e'){if(!isalpha(str[i+1]) && str[i-1] == 'l'){//-le;syllables++;continue;}else if(!isalpha(str[i+1]))//-e;continue;else if((str[i+1] == 'd' || str[i+1] == 's' ) && !isalpha(str[i+2]))//-ed,-es;continue;}if(!flag_frevowel){//当前字母为元音,但前一字符不是元音                    flag_frevowel = true;                    syllables++;                    continue;                }                else//当前字母为元音,但前一字母也是元音,即出现连续元音,syllable不计数                      continue;}flag_frevowel = false;//当前字母不是元音  }}cout<<fixed<<setprecision(2)<<206.835-1.015*(double)words/(double)sentences-84.6*(double)syllables/(double)words<<endl;return 0;}


0 0
原创粉丝点击