#C12497. Algebraic Expression Evaluator
Algebraic Expression Evaluator
Algebraic Expression Evaluator
This problem requires you to evaluate a series of basic algebraic operations given as strings. Each string represents a simple arithmetic expression that may include the operators +, -, * and /. Note that for division, you must perform integer division (i.e. using the floor division operator in Python or its equivalent in other languages). The expressions do not include parentheses and follow the standard operator precedence rules. All intermediate and final results are guaranteed to be integers.
In summary, you are given a list of arithmetic expressions and you must output the result for each one.
The division operation should be interpreted as \(\lfloor \frac{a}{b} \rfloor\) where the result is truncated towards zero in languages like C, C++, Java, and JavaScript.
inputFormat
The first line of input contains a single integer \(n\), which is the number of expressions. This is followed by \(n\) lines, each containing one arithmetic expression (a string) to evaluate.
For example:
4 2+2 4-1 6*3 8/2
outputFormat
For each arithmetic expression, output the evaluated integer result on a separate line. The order of outputs should correspond to the order of the given expressions.
For the above sample input, the output should be:
4 3 18 4## sample
4
2+2
4-1
6*3
8/2
4
3
18
4
</p>