


1. We consider the ‘/’ operator as the floor division.
2. Operators ‘*’ and ‘/’ expression has higher precedence over operators‘+’ and ‘-’
3. String expression always starts with ‘(‘ and ends with ‘)’.
4. It is guaranteed that ‘expression’ represents’ a valid expression in Infix notation.
5. It is guaranteed that there will be no case that requires division by 0.
6. No characters other than those mentioned above are present in the string.
7. It is guaranteed that the operands and final result will fit in a 32-bit integer.
Consider string ‘expression’ = ‘((2+3)*(5/2))’.
Then it’s value after evaluation will be ((5)*(2)) = 10.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next T lines represent the ‘T’ test cases.
The first and only line of each test case contains the string ‘expression’.
For each test case, in a separate line print an integer representing the value of the given arithmetic expression after evaluation.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
3 <= |expression| <= 10^4
Time limit: 1 sec
Infix Expressions are harder for Computers to evaluate because of the additional work needed to decide precedence, so we first convert infix expressions into either postfix or prefix expressions. In this approach, we convert Infix expression into Postfix expression also known as Reverse Polish Notation, and then evaluate the postfix expression using stack. Note in postfix expression, the operator is followed for every pair of operands.
For example, If the infix expression is (2+3) then its postfix expression will be 2 3+, we will use a single space to denote the end of one operand in the postfix expression.
We can alternatively convert the expression in prefix notation and then evaluate it, the approach will be similar to this one.