#K6361. Evaluate Arithmetic Expressions
Evaluate Arithmetic Expressions
Evaluate Arithmetic Expressions
You are given a list of arithmetic expressions that only contain single-digit integers and the operators +
, -
, *
, and /
. Your task is to evaluate each expression following the standard operator precedence, where multiplication and division are performed before addition and subtraction.
Note that the division operator /
represents integer division (i.e. floor division). Formally, for any two integers \(a\) and \(b\) (with \(b \ne 0\)), the expression \(a / b\) should be interpreted as \(\lfloor a / b \rfloor\).
For example, the expression 8/3
should evaluate to 2
because \(\lfloor8/3\rfloor = 2\).
inputFormat
The input is given via standard input (stdin). The first line contains an integer T
denoting the number of expressions. Each of the following T
lines contains one arithmetic expression.
Example:
3 1+2*3 4/2+6*2 7-4/2
outputFormat
For each expression, output the evaluated integer result on a separate line to standard output (stdout).
Example:
7 14 5## sample
1
1+2*3
7