Life, the Universe, and Everything

Practice this coding question on Coding Gurukul.

Problem statement

A laboratory console receives a stream of integer readings. The operator uses the value 42 as a stop signal rather than as a measurement. Any values sent after that signal belong to a later session and must not appear in the current report. Your program acts as a simple filter between the console and the report printer. Your task Read integers in order and print each one on its own line until the first 42 is encountered. Do not print the stopping value itself, and ignore every value after it. If the input ends before a stopping value appears, print all readings that were supplied. Important details The stop signal may be the first value, in which case the correct output is empty. Repeated measurements should be printed repeatedly. Do not sort, add or otherwise transform the measurements. Worked example For readings 7, 11, 42 and 9, print 7 and 11 on separate lines. The value 42 stops the report, and 9 is ignored.

Input format

A whitespace-separated stream of positive integers, usually one per line.

Output format

Print each integer preceding the first 42 on a separate line. The output may be empty.

Constraints

1 <= number of supplied values <= 10000; each value is 1..100.

Sample input

7
11
42
9

Sample output

7
11

Sign in to run or submit a solution in C++, Java or Python.