首页 > 专题系列 > Java解POJ > POJ 3371 Flesch Reading Ease [解题报告] Java
2013
11-12

POJ 3371 Flesch Reading Ease [解题报告] Java

Flesch Reading Ease

问题描述 :

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.

输入:

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 the Flesch Reading Ease score of the given passage rounded to two digits beyond decimal point.

样例输入:

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.

样例输出:

26.09

解题代码:

/* @author: */
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.Scanner;
import java.text.DecimalFormat;

class Main
{
  public static boolean isvowel(char a)
  {
     if (a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y')
	  return true;
     else
	  return false;
  }

  public static boolean isword(char a)
  {
    if (a==',' || a=='\'' || a=='"')
	  return true;
    else
	  return false;
   }

  public static boolean issen(char a)
  {
     if (a==':' || a==';' || a=='?' || a=='.' || a=='!')
	 return true;
     else
	 return false;
  }

  public static void main(String [] args) throws IOException
  {
    Scanner cin=new Scanner(new BufferedInputStream(System.in));
    DecimalFormat df=new DecimalFormat("0.00");
    String inp,temp;
    int word,wordnum=0,sentnum=0,sylnum=0,i,len;
    double score;
    boolean hasaddsyl,hasaddword,hasvow,sinquo,douquo;
    while (cin.hasNext())
    {
	inp=cin.next();
	temp=inp.toLowerCase();
	len=temp.length();
	word=0;
	hasaddsyl=false;
	hasaddword=false;
	hasvow=false;
	sinquo=false;
	douquo=false;
	for (i=0;i< len;i++)
	{
	  if (temp.charAt(i)>='a' && temp.charAt(i)<='z')
	   {
		word++;
		if ((word<=3) && ((i+1==len) || isword(temp.charAt(i+1)) || issen(temp.charAt(i+1))))
		{
	          word=0;
		   if (!hasvow)
			sylnum++;
		}
		else if (isvowel(temp.charAt(i)))
		{
		   hasvow=true;
		   if (!hasaddsyl)
		   {
			sylnum++;
			hasaddsyl=true;
		   }
		   else if (!isvowel(temp.charAt(i-1)))
		   {
			if (temp.charAt(i)=='e')
		       {
			  if (((i+1==len) || (temp.charAt(i+1)>'z') || 
			   (temp.charAt(i+1)< 'a')) && (temp.charAt(i-1)=='l'))
			 {
			   sylnum++;
			   continue;
			 }
			 if ((i+1==len) || ((temp.charAt(i+1)< 'a') || (temp.charAt(i+1)>'z')))
			   continue;
			 if ((i+1< len) && ((temp.charAt(i+1)=='s') || 
			   (temp.charAt(i+1)=='d')) && ((i+2==len) || 
			   (temp.charAt(i+2)>'z') || (temp.charAt(i+2)< 'a')))
			   continue;
			 else
			   sylnum++;
			}
			else
			  sylnum++;
		   }
	   }
	}
	else if (isword(temp.charAt(i)))
	{
		hasvow=false;
		if (temp.charAt(i)=='\'' && !sinquo)
		{
	         sinquo=true;
		  continue;
		}
		if (temp.charAt(i)=='"' && !douquo)
		{
		   douquo=true;
		   continue;
		}
		wordnum++;
		word=0;
		hasaddword=true;
		hasaddsyl=false;
	}
	else if (issen(temp.charAt(i)))
	{
	   wordnum++;
	   word=0;
	   hasvow=false;
	   if ((i+1< len) && temp.charAt(i)=='.' && temp.charAt(i+1)=='.')
		while ((i+1< len) && temp.charAt(i+1)=='.')
	         i++;
	   else
		sentnum++;
		hasaddword=true;
	}
    }
    if (!hasaddword)
		wordnum++;
  }
  score=206.835-1.015*((double)(wordnum)/(double)(sentnum))-84.6*((double)(sylnum)/(double)(wordnum));
  System.out.println(df.format(score));
 }
}

  1. 我没看懂题目
    2
    5 6 -1 5 4 -7
    7 0 6 -1 1 -6 7 -5
    我觉得第一个应该是5 6 -1 5 4 输出是19 5 4
    第二个是7 0 6 -1 1 -6 7输出是14 7 7
    不知道题目例子是怎么得出来的

  2. 给你一组数据吧:29 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1000。此时的数据量还是很小的,耗时却不短。这种方法确实可以,当然或许还有其他的优化方案,但是优化只能针对某些数据,不太可能在所有情况下都能在可接受的时间内求解出答案。