#K94397. Evaluate Arithmetic Expression

    ID: 38632 Type: Default 1000ms 256MiB

Evaluate Arithmetic Expression

Evaluate Arithmetic Expression

You are given an arithmetic expression in the form of a string. This expression contains non-negative integers (0-9), the operators \(+, -, *, /\), and parentheses \((, )\). Your task is to evaluate the expression while respecting the standard operator precedence and associativity. Note that division should perform integer division (i.e. truncate the result toward zero).

For example, the expression 3+5*2 should be evaluated as 13, and the expression (2+3)*(5-1) should be evaluated as 20. Handle spaces appropriately.

You will receive multiple expressions and you must output the result of each expression on a new line.

inputFormat

The input begins with a single integer (T) (the number of test cases). Each of the following (T) lines contains one arithmetic expression to evaluate.

outputFormat

For each test case, output a single line containing the integer result after evaluating the given expression.## sample

4
3+5
3+5*2
(2+3)*(5-1)
10/(2+3)
8

13 20 2

</p>