
1) An integer “A”: Introduce a new score of ‘A’ on the track record.
2) "+": Introduce a new score on the track record that is the sum of the previous two scores.
3) "C": Nullify the previous score, removing it from the track record.
4) "D": Introduce a new score on the track record that is double the previous score.
It is guaranteed there will always be a previous score before the “C” and “D” operations and two previous scores before the “+” operation.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the number of operations in the list of strings, ‘MATCHRESULT’.
The next line of each test case contains ‘N’ space-separated strings representing the operations in the list of strings, ‘MATCHRESULT’.
For each test case, return the sum of all the scores on the track record.
The output of each test case will be printed in a separate line.
1 <= T <= 5
1 <= N <= 1000
MATCHRESULT[ i ] ∈ {[-3 * 10 ^ 4, 3 * 10 ^ 4], “+”, “C”, “D”}
Where ‘T’ is the number of test cases, ‘N’ is the number of operations in the list of strings, ‘MATCHRESULT’ and ‘MATCHRESULT[ i ]’ is the ‘i’th operation in the list of strings, ‘MATCHRESULT’.
Time limit: 1 second.
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea is to use the brute force approach. We will traverse the list of strings, ‘MATCHRESULT’ and introduce the score in the ‘TRACKRECORD’ as per the given conditions.