A retro arcade's scoring console keeps a single running score and updates it through a scripted chain of commands, one after another, the same way an operator would call one fluent method after the next without ever resetting the value in between. Starting from a given initial score, you must replay the command sequence in order. Five commands mutate the running score -- add a value, subtract a value, multiply by a value, divide by a value, and raise the score to an integer power -- while a sixth command, a checkpoint, asks you to record the current score without changing it. Your task is to report the score recorded at every checkpoint, in the order the checkpoints occur.
n, the number of commands in the chain.init, the starting score.n lines is one command, in one of these forms:
ADD x -- add x to the running score.SUB x -- subtract x from the running score.MUL x -- multiply the running score by x.DIV x -- divide the running score by x.POW k -- raise the running score to the integer power k.CHECK -- record the current running score (the score itself is left unchanged).Print one line for every CHECK command, in the order the CHECK commands appear in the input. Each line must contain the recorded score formatted to exactly 4 digits after the decimal point.
1 <= n <= 1000CHECK command.init and every operand x are real numbers (may include a sign and a fractional part) with absolute value at most 10^6.DIV x command, x != 0.POW k command, k is an integer with 0 <= k <= 10.10^15 at any point while processing the commands, so ordinary 64-bit floating point arithmetic is always sufficient and never overflows.Example 1
Input
5 10 ADD 5 CHECK MUL 2 CHECK SUB 3
Expected
15.0000 30.0000
Explanation
The score starts at 10. ADD 5 makes it 15, and the first CHECK records 15.0000. MUL 2 makes it 30, and the second CHECK records 30.0000. The final SUB 3 changes the score to 27, but there is no checkpoint after it, so it is never reported.
Example 2
Input
4 2 DIV 4 POW 3 CHECK ADD 1.5
Expected
0.1250
Explanation
The score starts at 2. DIV 4 makes it 0.5. POW 3 raises it to 0.5^3 = 0.125, and the CHECK records 0.1250. The final ADD 1.5 changes the score to 1.625, but there is no checkpoint after it, so it is never reported.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →