程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> poj3371--Flesch Reading Ease(模擬)

poj3371--Flesch Reading Ease(模擬)

編輯:C++入門知識

poj3371--Flesch Reading Ease(模擬)


Flesch Reading Ease Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1882 Accepted: 553

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.

Periods, explanation points, colons and semicolons serve as sentence delimiters. Each group of continuous non-blank characters with beginning and ending punctuation removed counts as a word. Each vowel (one of a, e, i, o, u and y) in a word is considered one syllable subject to that
    -es, -ed and -e (except -le) endings are ignored, words of three letters or shorter count as single syllables, consecutive vowels count as one syllable.

    References

    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. 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

    給出一段標准英語,統計裡面的單詞數,句子數,音節數,通過公式算出結果。

    標准符號 ',' ' ' '.' ';' ':' '!' '?' 全是英語符號 逗號,空格,只分割單詞。句號,分號,冒號,歎號,問號,分割句子和單詞。

    統計字節的時候:

    1、單詞長度小於等於3是,音節為1

    2、大於3是,每個原音字母a,e,i,o,u,y,區分大小寫,每個都是一個音節,如果結尾以-e(-le不算),-es,-ed結尾e不被記為一個音節。

    #include 
    #include 
    #include 
    using namespace std ;
    char str[1000] ;
    int a , b , c ;//a單詞數,b句子數,c音節數
    int find1(char ch)
    {
        if( ch == ',' || ch == ' ' )
            return 1 ;
        if( ch == '.' || ch == '?' || ch == ':' || ch == ';' || ch == '!' )
            return 2 ;
        if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y' )
            return 3 ;
        if( ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'Y' )
            return 3 ;
        return 0 ;
    }
    void solve(int i,int num,int c_num)
    {
        if( num <= 3 )
        {
            c++ ;
            return ;
        }
        if( str[i] == 'e' )
        {
            if( str[i-1] == 'l' || find1(str[i-1]) == 3 )
                c += c_num ;
            else
                c += (c_num-1) ;
        }
        else if( (str[i-1] == 'e' && str[i] == 's') || (str[i-1] == 'e' && str[i] == 'd') )
        {
            if( find1(str[i-2]) == 3 )
                c += c_num ;
            else
                c += (c_num-1) ;
        }
        else
            c += c_num ;
        return ;
    }
    int main()
    {
        int i , l , num , c_num , flag , k ;
        a = b = c = 0 ;
        while( scanf("%s", str) != EOF )
        {
            l = strlen(str) ;
            flag = num = c_num = 0 ;//flag當前字符的前一個字符是不是原音,num當前單詞的字母數,c_num單詞原音數
            for(i = 0 ; i < l ; i++)
            {
                k = find1(str[i]) ;
                if( k == 0 )
                {
                    num++ ;
                    flag = 0 ;
                }
                else if( k == 1 )
                {
                    a++ ;
                    solve(i-1,num,c_num) ;
                    flag = num = c_num = 0 ;
                }
                else if( k == 2 )
                {
                    a++ ;
                    b++ ;
                    solve(i-1,num,c_num) ;
                    flag = num = c_num = 0 ;
                }
                else if( k == 3 )
                {
                    num++ ;
                    if( flag == 0 )
                    {
                        c_num++ ;
                        flag = 1 ;
                    }
                }
            }
            k = find1(str[l-1]) ;
            if( k == 0 || k == 3 )
            {
                a++ ;
                solve(l-1,num,c_num) ;
            }
        }
        printf("%.2lf\n", 206.835 - 1.015*(a*1.0)/(b*1.0) - 84.6*(c*1.0)/(a*1.0) );
        return 0;
    }
    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved