Number Bicycle
View as PDFA number bicycle is a made up term that defines this program's input. Below is an image of a bicycle that may be safely ignored:
__o
_`\<,_
(*)/ (*)
Any mention of "integer" in this text refers to a valid Java integer, according to the official documentation.
Additionally, at no point will an integer overflow or underflow occur if a correct solution is used.
Input Specification
Given a starting integer , keep reading lines that contain a single integer
, adding it to
.
Continue reading lines until a line containing the integer appears, where
is equal to the running total
.
Then, keep reading lines that contain a single integer , multipling
by
.
Continue reading lines until a line containing the integer appears, where
is equal to the running total
.
Finally, keep reading lines that contain a single integer , dividing
by
and then setting
to the floor* of
.
*The floor of a real number is the largest integer less than or equal to
. For example, the floor of
is
.
Notice
Any line that would normally contain the integer may contain either the strings
QUIT or KILL.
One can safely ignore all lines that contain the string QUIT.
Once the line KILL appears, output . One, and only one,
KILL string will appear in the input.
Output Specification
Upon the line KILL appearing instead of a line containing , output
.
Subtasks
Subtask 1 [20%]
No QUIT lines; KILL is the last line of input.
Subtask 2 [80%]
No further restrictions.
Sample Input
1
3
2
6
2
1
12
5
KILL
Sample Output
2
Sample Explanation
Below is a line by line explanation of the input:
1 // Sets N to 1 --- Addition Phase ---
3 // 1 + 3 = 4
2 // 4 + 2 = 6
6 // 6 = 6 --- Multiplication Phase ---
2 // 6 * 2 = 12
1 // 12 * 1 = 12
12 // 12 = 12 --- Division Phase ---
5 // 12 / 5 = 2.4, the floor of which is 2
KILL // Output "2"
Thus, the correct output is 2.
Comments