10126 - Zipf's Law

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh

Post by ayon »

most probably online-judge doesn't support clear()
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program

lena
New poster
Posts: 28
Joined: Mon Mar 05, 2007 5:44 pm

Post by lena »

ayon wrote:most probably online-judge doesn't support clear()
could somebody give a specification on the environment of online-judge?

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

ayon wrote:most probably online-judge doesn't support clear()
It does.

std::string comes from <string>, not from <cstring> (although you need the latter for strcmp (although operator== could do the trick with much less typing)).
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

lena
New poster
Posts: 28
Joined: Mon Mar 05, 2007 5:44 pm

Post by lena »

solved.thank you.when i didnot include the <string> library,the compiler didnot give any warning...,so i submit a wrong code.

mirage
New poster
Posts: 11
Joined: Sat Jan 19, 2008 9:37 pm

Wrong answer.....10126

Post by mirage »

hi friends,
i m gettin wrong answer on the OJ for this easy prob........the program is passing the test that i gave it n the one ones i found in the forums.....
still unable to find the bug....plz help......
is thr any special way to print the output for this prob...
here's the code:

Code: Select all

//Zipf's law 
#include<iostream> 
#include<map> 
#include<string> 
using namespace std; 
int main(){ 
   int n; 
   int count=0; 
   while(cin>>n){ 
      if(count++!=0) cout<<"\n"; 
      string s; 
      int loop=1; 
      map<string,int> maps; 
      while(loop==1){    
         getline(cin,s,'\n'); 
         s=s+" ";    
         int i=0; 
         while(i<s.length()){ 
            string h=""; 
            int val=s[i]; 
            string alias=""; 
            while((val>=65 && val<=90)|| (val>=97 && val<=122)){ 
               if(val>=90) h=h+s[i]; 
               else h=h+char(s[i]+32); 
               alias=alias+s[i++]; 
               val=s[i]; 
            } 
            i++; 
            if(alias=="EndOfText"){ 
               loop=0; 
               break; 
            } 
            maps[h]=maps[h]+1; 
         } 
      } 
      map<string,int>::iterator iter; 
      iter=maps.begin(); 
      int l=0; 
      while(iter!=maps.end()){ 
         if(iter->second==n) { 
            cout<<iter->first<<"\n"; 
            l=1; 
         } 
         iter++; 
      } 
      if(l==0) cout<<"There is no such word."<<"\n"; 
      maps.clear(); 
   } 
   return(0); 
} 

Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10126 - Zipf's Law

Post by Jehad Uddin »

read the problems output specification,
For each test case, output the words which occur n times in the input text, one word per line, lower case, in alphabetical order

sd12582000
New poster
Posts: 1
Joined: Sat May 19, 2012 1:49 pm

Re: 10126 - Zipf's Law

Post by sd12582000 »

try
input
2
a-a
EndOfText
output
a

Post Reply

Return to “Volume 101 (10100-10199)”