Why interactive task running idle?

Правка en2, от shanto_bangladesh, 2022-04-14 04:08:36

I tried to solve the following interactive problem: Problem link

Please focus in the main() function:

bool testcase =          0               ;
void solve()
{   
int hi = 1000000, lo = 1, mid;
    string s; 
    while(lo+1<hi)
    {
        mid = (lo+hi)/2;
        cout << mid << "\n";
        fflush(stdout);
        cin >> s;
        if(s[0]=='<') { hi = mid-1; }
        else { lo = mid; }
    }
    cout << hi << "\n";
    fflush(stdout);
    cin >> s;
    if(s[0]=='>') cout << "! " << hi << "\n";
    else cout << "! " << lo << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   int t = 1; 
   if(testcase == true)
   {
  cin >> t;
   }
    while(t--)
   {
       solve();
   }
} 

When I ran the above piece of code in Visual Studio code terminal it didn't produce any output. Then I deleted those 2 lines in the main function.

  ios_base::sync_with_stdio(0);
    cin.tie(0);

Then it ran nicely producing desired output. Why it didn't work with those 2 lines of code?

Any insight will help a lot. Thanks for your patience.

Теги syntax, interactive-problem, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский shanto_bangladesh 2022-04-14 04:08:36 86 (published)
en1 Английский shanto_bangladesh 2022-04-14 04:03:40 1167 Initial revision (saved to drafts)