10126 - Zipf's Law
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
It does.ayon wrote:most probably online-judge doesn't support clear()
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...
Wrong answer.....10126
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:
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);
}
-
- Learning poster
- Posts: 74
- Joined: Fri May 08, 2009 5:16 pm
Re: 10126 - Zipf's Law
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
For each test case, output the words which occur n times in the input text, one word per line, lower case, in alphabetical order
-
- New poster
- Posts: 1
- Joined: Sat May 19, 2012 1:49 pm
Re: 10126 - Zipf's Law
try
input
a
input
output2
a-a
EndOfText
a