Flesch Reading Ease(模拟)

http://poj.org/problem?id=3371

终于遇到简单一点的模拟题了。不过本人真心没有耐心读题目。。。

它的大致意思就是给一段合法的文章,求出这段文章的单词数,句子数,音节数,按照题目给出的公式带入就出结果。

>因为输入是按空格作为字符串结束标志的,因此每输入一个字符串就是一个单词,

>句子结束的标志是 . ? : ; !五种,每输入一个字符串只须判断其最后一个字符是否是 . ? : ; !的一种,若是,句子数加1.

>对于音节数,单词长度<=3的为一个音节,

大于3的情况下,句子中有元音 a(A),e(E),i(I),o(O),u(U),y(Y)时音节数加1,但如果有连续的元音字母按1个算,如果单词以 -es 或 -ed 或 -e(不包括-le)结尾,不算一个音节。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<ctype.h>
 5 using namespace std;
 6 
 7 bool check_sentences(char ch)
 8 {
 9     if(ch == '.' || ch == '?' || ch == ':' || ch == ';' || ch == '!')
10         return true;
11     return false;
12 }
13 
14 bool check_syllables(char ch)
15 {
16     if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'
17     || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'Y')
18         return true;
19     return false;
20 
21 }
22 
23 int main()
24 {
25     int sentences = 0;//句子数
26     int words = 0;//单词数
27     int syllables = 0;//音节数
28     int len,i;
29     char s[50];
30 
31     while(cin>>s)
32     {
33         len = strlen(s);
34 
35         if(check_sentences(s[len-1]))
36             sentences++;
37 
38         words++;
39 
40         while(!isalpha(s[len-1]))
41             len--;
42 
43         if(len <= 3)
44             syllables++;//单词长度<=3时,音节数加1
45         else
46         {
47             if(check_syllables(s[0])) syllables++;
48 
49             for(i = 1; i < len; i++)
50             {
51                 if(check_syllables(s[i]) && !check_syllables(s[i-1]))
52                     syllables++;
53             }
54             //去除以 -es -ed -e(除-le)结尾的情况
55             if(!check_syllables(s[len-3]) && s[len-2] == 'e' && (s[len-1] == 's'|| s[len-1] == 'd'))
56                 syllables--;
57             if(!check_syllables(s[len-2]) && s[len-1] == 'e' && s[len-2] != 'l')
58                 syllables--;
59         }
60     }
61     double ans;
62     ans = 206.835-1.015*(words*1.0/sentences)-84.6*(syllables*1.0/words);
63     printf("%.2lf
",ans);
64     return 0;
65 }
View Code
原文地址:https://www.cnblogs.com/LK1994/p/3397679.html