Flesch Reading Ease(模拟)
http://poj.org/problem?id=3371
1 #include <iostream> 2 #include <iomanip> 3 #include <cstring> 4 using namespace std; 5 const int N=102; 6 bool is_sen(char ch)//判断是否为句子 7 { 8 if (ch=='.'||ch=='!'||ch=='?'||ch==':'||ch==';') 9 return true; 10 return false; 11 } 12 bool is_vowel(char ch)//判断是否是元音 13 { 14 if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='y') 15 return true; 16 return false; 17 } 18 int main() 19 { 20 char msg[N],world[N]; 21 int sen = 0,worlds = 0,syl = 0; 22 while(cin>>msg) 23 { 24 worlds++;//单词计数 25 int len = strlen(msg); 26 for(int i = 0; i < len; i++) 27 { 28 if (msg[i]>='A'&&msg[i]<='Z') 29 msg[i]=msg[i]-'A'+'a'; 30 else if (is_sen(msg[i])) 31 sen++;//句子计数 32 } 33 int l = len; 34 int s = 0,k = 0; 35 while(!(msg[l]>='a'&&msg[l]<='z')) --l; 36 while(!(msg[s]>='a'&&msg[s]<='z')) ++s; 37 for (int i = s; i <= l; i++) 38 { 39 world[k++] = msg[i]; 40 } 41 world[k]='\0'; 42 if (k<=3) syl++;//音节计数 43 else 44 { 45 46 if (world[k-2]=='e'&&(world[k-1]=='s'||world[k-1]=='d')) 47 k-=2; 48 else if (world[k-2]!='l'&&world[k-1]=='e') 49 k-=1; 50 if (is_vowel(world[0])) syl++; 51 for (int i = 1; i < k; i++) 52 { 53 if (is_vowel(world[i])&&!is_vowel(world[i-1])) 54 syl++; 55 } 56 } 57 58 } 59 double ans = 206.835 - 1.015*worlds/sen - 84.6*syl/worlds; 60 cout<<fixed<<setprecision(2)<<ans<<endl; 61 return 0; 62 }