Score Log Replay
A game's scoring service replays an operations log to rebuild the round's running tally. Each entry is an integer to record, '+' to add the last two recorded scores, 'D' to double the last score, or 'C' to cancel the last score. Return the final total.
Problem
Given a list of operation tokens, process each: an integer records that value; 'C' removes the last recorded value; 'D' records double the last value; '+' records the sum of the last two values. Return the sum of all values still recorded.
Input
An array ops of length n (1 ≤ n ≤ 1000); each token is an integer string, 'C', 'D', or '+'.
Output
A single integer — the sum of the remaining recorded values.
Constraints
- Operations are always valid for the current state
- Integer values fit in a 32-bit int
- 1 ≤ n ≤ 1000
Examples
Example 1
Input
ops = ["5", "2", "C", "D", "+"]
Output
30
Record 5, record 2, cancel 2 → [5]; D doubles → [5,10]; + sums last two → [5,10,15]; total 30.
Example 2
Input
ops = ["1", "C"]
Output
0
Record 1 then cancel it — nothing remains.