You keep the score sheet for a baseball game with unusual rules. You are given a list of strings `operations`, applied in order to an initially empty record. An integer `x` records a new score of `x`. `"+"` records a new score equal to the sum of the previous two scores. `"D"` records a new score equal to double the previous score. `"C"` removes the previous score from the record. Return the sum of all scores left on the record after every operation. All operations are valid, and every intermediate value and the answer fit in a 32-bit integer.
You keep the score sheet for a baseball game with unusual rules. You are given a list of strings operations, applied in order to an initially empty record. An integer x records a new score of x. "+" records a new score equal to the sum of the previous two scores. "D" records a new score equal to double the previous score. "C" removes the previous score from the record. Return the sum of all scores left on the record after every operation. All operations are valid, and every intermediate value and the answer fit in a 32-bit integer.
Example 1:
Input: {"operations":["5","2","C","D","+"]}
Output: 30
Constraints:
1≤operations.length≤1000
operations[i] is "C", "D", "+", or a string for an integer in the range [−3×104,3×104].
For "+", there are always at least two previous scores on the record.
For "C" and "D", there is always at least one previous score on the record.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"operations":["5","2","C","D","+"]}
operations
5
2
C
D
+
Start with an empty score sheet. Every operation only looks at the most recent scores, so the sheet is a stack.