EXPECT - Life, the Universe, and Everything (Interactive)

Note for Interactive problem setters: if you are stucked on how to write a interactive problem judge, you may send a mail to "blue.mary.me@qq.com". It will send you the custom judge of this problem.

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Interactive Protocol

You should communicate with Judge using standard input and output.

Attention: the program should clear the output buffer after printing each line.

It can be done using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout).

Each time the judge will give you a number. You should rewrite this number to standard output. If this number equals 42, after rewriting your program should terminate immediately.

Example

The example of communication.

Input:
3
15
42

Output:
3
15
42

Attention: the program should clear the output buffer after printing each line.

Reference

Please pay attention that: your program should NOT output any extra characters like "J","P" or “:". Follow the interactive protocol strictly. A sample program (in C++) that can get Accepted is as the following:


Added by:Fudan University Problem Setters
Date:2008-05-24
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL GOSU JS-RHINO NODEJS PERL6 VB.NET
Resource:A sample of Interactive problems

hide comments
2024-11-02 02:07:32
solved

Last edit: 2024-11-02 02:14:00
2021-10-19 18:45:07
Look at the statistics & best solutions from this problem. I've only seen 1 python solution solved and I went through 16 pages.

Last edit: 2021-10-19 20:01:43
2021-06-22 08:52:04
Doesnt accept any solution !!
2021-02-28 10:49:22
Why the code is getting tle if fflush(stdout) is not used?
2020-08-17 04:42:15
hey guys for python use print(number,flush=True)
2020-05-13 03:37:22
Works on thonny but exceeds the time limit?
2020-02-11 18:25:53
as in ideone we give the manual input but how does it vary when coming to the time limit error
2019-12-28 03:43:15
Don't bother with arrays or anything, just read the input and print it.
2019-12-28 03:40:30
confused as to why i am getting TLE in python.
2019-11-21 10:46:23
no need of flushing, use <<endl.
It's not complicated, just take inputs, no need of writing output. No arrays or other shit.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.