Loading...
Loading...
Loading...
A game records scores from tokens. A number adds that score. C cancels the previous score. D adds a score double the previous one. + adds a score equal to the sum of the previous two. Print the total of all scores that remain.
Example 1
Input
5 2 C D +
Output
30
Scores become 5, 2, then 5, then 5 10, then 5 10 15. The total is 30.
Example 2
Input
5 -2 4 C D 9 + +
Output
27
Try the problem first. Open one hint at a time.
Keep the scores in a list used as a stack.
C pops, D reads [-1], and + reads [-1] and [-2].
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor