#K48572. Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
You are given an arithmetic expression as a string. The expression consists of non-negative integers and the operators \( +, -, \times, \div \) (i.e. '+', '-', '*', '/'). The expression does not include any parentheses. Operator precedence follows the standard rules: multiplication and division are performed before addition and subtraction. Division is integer division (truncating toward zero).
For example, the expression 3+2*2
is evaluated as 3+(2*2)=7
, and 3/2
evaluates to 1
(since 1.5 truncates to 1).
Your task is to evaluate each given expression and output its result as an integer.
inputFormat
The input is read from standard input. The first line contains an integer \( N \), denoting the number of expressions. Each of the following \( N \) lines contains a single arithmetic expression.
For example:
3 3+2*2 3/2 3+5 / 2
outputFormat
For each expression in the input, output its evaluated result on a new line. All output should be written to standard output.
For the above example, the output should be:
7 1 5## sample
3
3+2*2
3/2
3+5 / 2
7
1
5
</p>