Interactive problems rely on the communication of two programs: one that you write the other that the problem author writes. Your program needs to interact with the problem author’s program to solve the problem described in the statement.
Here is an example of what an interactive problem would be like: https://toph.co/p/an-obvious-interactive-problem
To ensure that anything your program outputs reach the driver program written by the problem author (and is not held in any internal buffer) you need to flush your output.
Every programming language has its own way of dealing with this. Below you can find some examples.
When using printf()
, "\n"
causes the output buffer to be flushed:
|
|
To force flush the output buffer, fflush()
can be used on stdout
:
|
|
Buffering on stdout
can be disabled entirely by using setbuf()
:
|
|
When using cout
, endl
causes the output buffer to be flushed:
|
|
Alternatively you can use flush
:
|
|
If you prefer using printf
in C++, you will have to use fflush()
on stdout
(even with newline character in the format specification):
|
|
Or, disable buffering on stdout
entirely using setbuf()
:
|
|
You do not need to do anything extra as long as you are using print
without any trailing comma.
You do not need to do anything extra as long as you are using print()
without end=""
.
|
|
|
|