POJ 3371 英语16级阅读

  1 //Result:wizmann    3371    Accepted    704K    0MS    G++    1699B    
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <algorithm>
6 #include <iostream>
7
8 //Test data:
9 //A. Ole drei end dead fucked. AES. DES. Maerlyn's. Gute. TTOLE.
10
11 using namespace std;
12
13 #define print(x) cout<<x<<endl
14 #define input(x) cin>>x
15
16 #define EOS 1
17 //The end of sentence
18
19 #define VOVEL 2
20 //The vovel
21
22 #define ASC 256
23 #define BUFFER 128
24
25 char mark[ASC];
26
27 void init()
28 {
29 memset(mark,0,sizeof(mark));
30 mark['a']=mark['e']=mark['i']=mark['o']=mark['u']=mark['y']=VOVEL;
31 mark['.']=mark['!']=mark['?']=mark[':']=mark[';']=EOS;
32 }
33
34 int sentence,word,vovel;
35
36
37 void check(char* buffer)
38 {
39 int res=0;
40 int len=strlen(buffer);
41 if(mark[buffer[len-1]]==EOS)
42 {
43 sentence++;
44 buffer[len-1]='\0';
45 len--;
46 }
47 while(buffer[len-1]<'a' || buffer[len-1]>'z')
48 {
49 buffer[len-1]='\0';
50 len--;
51 }
52 if(len<=3) res=1;
53 else
54 {
55 if(buffer[len-2]=='e')
56 {
57 if(buffer[len-1]=='s' || buffer[len-1]=='d')
58 {
59 buffer[len-2]='\0';
60 len-=2;
61 }
62 }
63 else if(buffer[len-1]=='e')
64 {
65 if(buffer[len-2]!='l')
66 {
67 buffer[len-1]='\0';
68 len--;
69 }
70 }
71 for(int i=0;buffer[i];i++)
72 {
73 if(mark[buffer[i]]==VOVEL)
74 {
75 if(i==0) res++;
76 else if(mark[buffer[i-1]]!=VOVEL) res++;
77 }
78 }
79 }
80 vovel+=res;
81 word++;
82 }
83
84 double cal()
85 {
86 return 206.835-1.015*((double)word/sentence)-84.6*((double)vovel/word);
87 }
88
89 int main()
90 {
91 freopen("input.txt","r",stdin);
92 char buffer[BUFFER];
93 init();
94 sentence=word=vovel=0;
95 while(scanf("%s",buffer)!=EOF)
96 {
97 for(int i=0;buffer[i];i++)
98 {
99 if(buffer[i]>='A' && buffer[i]<='Z')
100 {
101 buffer[i]=buffer[i]-'A'+'a';
102 }
103 }
104 check(buffer);
105 }
106 printf("%.2f\n",cal());
107 return 0;
108 }

你可能感兴趣的:(poj)