Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <map>
- #include <cmath>
- #include <cstring>
- #include <sstream>
- #include <string>
- using namespace std;
- map<string,int>m;
- int total;
- void Procesar(string & s){
- for (unsigned int i=0;i<s.size();i++){
- if ((s[i]==',') || (s[i]=='.') ||(s[i]==';') ||(s[i]=='(') ||(s[i]==')') ||(s[i]==':') ||(s[i]=='?') ||(s[i]=='!') ||(s[i]=='"'))
- s[i]=' ';
- else if (s[i]>='A' && s[i]<='Z')
- s[i]=s[i]+'a'-'A';
- }
- istringstream ss(s);
- string w;
- while (ss >> w) {
- m[w]++;
- //cout<<w<<endl;
- total++;
- }
- }
- int main(){
- char s1[100];
- while(gets(s1)){
- //cout<<s1<<endl;
- string s(s1);
- if (s=="****END_OF_INPUT****") break;
- m.clear();total=0;
- if (s=="****END_OF_TEXT****"){
- printf("0 0.0 0\n");
- continue;
- }
- while (s!="****END_OF_TEXT****"){
- //cout<<s1<<endl;
- Procesar(s);
- //printf("s:-%s-",s);
- gets(s1);
- s=string(s1);
- }
- float et=0,gg=log10(total);
- for (map<string,int>::iterator it=m.begin(); it!=m.end(); it++){
- et=et+(it->second)*( gg - log10(it->second));
- }
- et=et/total;
- float erel=et/log10(total)*100.0;
- if (total==0)
- printf("0 0.0 0\n");
- else
- printf("%d %.1f %.0f\n",total,et,erel);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment