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

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

I was learning about interactive problems, and I solved a few problems such as:

1. Guess the Number

E. Interview

I also read this blog:

Interactive Problems: Guide for Participants

I learned that you have to use either endl or cout.flush() after "\n".

However, I tried not using cout.flush() at all and just used "\n" or endl.

Now, endl works because it includes the flush operation, but why is "\n" working without cout.flush()?

Are interactive problems only interactive during live contests?

Can someone please try solving the above two problems with "\n" and no cout.flush() and explain this behavior to me?

Here are my solutions with "\n" only:

1. Guess the Number

E. Interview

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

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

Maybe, MikeMirzayanov can answer

»
3 часа назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

cin is usually by default tied to cout (check this comment). This means that prior to calling cin, the program ensures that all the output from cout was flushed. So (at least in C++) you only really need to call cout.flush() if you wrote cin.tie(0) in the beginning of your code. I assume all the flushing disclaimers are there to ensure that people coding in other languages (or C++ users who just copy-paste cin.tie(0) without knowing what it does) flush the output and don't get WA for no reason.