Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя catismyfav

Автор catismyfav, история, 4 года назад, По-английски

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;

~~~~~

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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