catismyfav's blog

By catismyfav, history, 5 years ago, In English

Hello! I was trying this problem Bear and Prime 100. I have used fflush(stdout) but it is showing idleness limit exceeded. Please help me with this. Here is the code and submission link ~~~~~

int square[] = {4,9,25,49};
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int div=0;
for(int i=0;i<15;i++){
    cout<<primes[i]<<endl;
    fflush(stdout);
    string response;
    cin>>response;
    if(response[0]=='y') div++;
}
if(div>=2){
    cout<<"composite"<<endl; return ;
}
div=0;
for(int i=0;i<4;i++){
    cout<<square[i]<<endl;
    fflush(stdout);
    string response;
    cin>>response;
    if(response[0]=='y') div++;
}
if(div){
    cout<<"composite"<<endl; return;
}
cout<<"prime"<<endl;

~~~~~

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it -6 Vote: I do not like it

Removing fast i/o worked for me. I think cin flushes automatically unless you have cin.tie(0).

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Use cout.flush(), this is what works for cout. See 80256006 for AC using it.