Number Bicycle

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types

A 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 N, keep reading lines that contain a single integer K, adding it to N.

Continue reading lines until a line containing the integer K appears, where K is equal to the running total N.

Then, keep reading lines that contain a single integer K, multipling N by K.

Continue reading lines until a line containing the integer K appears, where K is equal to the running total N.

Finally, keep reading lines that contain a single integer K, dividing N by K and then setting N to the floor* of N.

*The floor of a real number A is the largest integer less than or equal to A. For example, the floor of -1.1 is -2.

Notice

Any line that would normally contain the integer K 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 N. One, and only one, KILL string will appear in the input.

Output Specification

Upon the line KILL appearing instead of a line containing K, output N.

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

There are no comments at the moment.