forked from dseco/acmudec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path860.cpp
68 lines (67 loc) · 2.06 KB
/
860.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;
int main() {
string s;
while(getline(cin, s)) {
if(s.substr(0, 20) == "****END_OF_INPUT****")
return 0;
map<string, int> r;
int lambda = 0;
do {
if(s == "****END_OF_TEXT****")
break;
int i, len = s.length();
for(i = 0; i < len; i++) {
if(!isalpha(s[i]))
continue;
string word = "";
int j(i);
while(j < len) {
bool flag = false;
switch(s[j]) {
case ',':break;
case '.':break;
case ':':break;
case ';':break;
case '!':break;
case '?':break;
case '\"':break;
case '\t':break;
case '(':break;
case ')':break;
case ' ':break;
case '\n':break;
case EOF:break;
case '\0':break;
default:
if(isupper(s[j]))
s[j] += 32;
word += s[j];
flag = true;
}
if(!flag)
break;
j++;
}
//cout << word << endl;
i = j;
lambda++;
r[word]++;
}
} while(getline(cin, s));
double Et = 0, Emax = log10(lambda);
for(map<string, int>::iterator it = r.begin(); it != r.end(); it++) {
Et += it->second*(log10(lambda)-log10(it->second));
}
Et /= lambda;
if(lambda == 0)
puts("0 0.0 0");
else
printf("%d %.1lf %.0lf\n", lambda, Et, Et*100/Emax);
}
return 0;
}