


Consider STR = “3+2*2”
Using the BODMAS rule, the expression after evaluation gives 7. Hence, the answer is 7.
The first line of input contains an integer ‘T’, denoting the number of test cases. Then each test case follows.
The first line of each test case contains a string ‘STR’, which represents the given expression.
For each test case, print a single integer representing the value of the given expression.
The output of each test case will be printed on a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |STR| <= 10 ^ 6
‘STR’ consists of integers and operators (+, -, \, *).
‘STR’ represents a valid expression.
All the integers in the expression are non-negative integers in the range [0, 10 ^ 8].
Time Limit: 1 sec.
The evaluated string is always less than or equal to 10 ^ 9.
Scan the input string ’STR’ from left to right and evaluate the expressions based on the following rules:
The steps are as follows:
In the previous approach, we used a stack to track the values of the evaluated expressions. In the end, we delete all the values from the stack and add them to the result. Instead of that, we could add the values to the result beforehand and keep track of the last calculated number, thus eliminating the need for the stack.