How do interactive problems work?

Just as in non-interactive problems, you will receive input from stdin and 
print output to stdout. Our system will do the job of directing your output 
stream to the judge's input stream, and pointing the judge's output stream 
to your input stream. However, every time you output data, *you must flush 
your output buffer*, as explained below.

-------------------

The reason why it is not working with *printf*, is because *STDOUT* is a 
buffered stream and it doesn't get flushed until the buffer is full or you 
manually triggered a flush.
Without flushing the stream, the other program will not receive your data 
and therefore cannot send more data to your program.
And your program wants to read the response and hence causes a deadlock.

It was like your postman is holding your mail and waiting for more mail to 
come in (because he wants to send all mails in a batch) and you are waiting 
for the response that never comes.

To solve this, simply flush your stream (like asking your postman to 
deliver your mail without waiting for more mails)

The reason why *cout* would work is because whenever a *std::endl* is sent 
to the stream, it also triggered a flush so you don't have to manually do 
that.
In other word, the following code will also fail for the same reason.

*cout << something << '\n';*

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/1efcb358-48a8-4939-9380-ff2327b3d1c2%40googlegroups.com.

Reply via email to