#C12643. Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
You are given a string representing a mathematical expression containing non-negative integers and the operators +
, -
, *
, and /
(integer division). Your task is to evaluate the expression correctly while respecting the standard operator precedence rules. Multiplication and division have a higher precedence than addition and subtraction. Note that the division operation is defined as $\lfloor \frac{a}{b} \rfloor$, with the division result truncated towards zero.
Examples:
3+5 / 2
evaluates to5
.3 + 2 * 2
evaluates to7
.12 + 3 / 3 * 2
evaluates to14
.100
evaluates to100
.1 - 1 + 1
evaluates to1
.
Implement a solution that reads the expression from standard input and outputs the computed result to standard output.
inputFormat
The input consists of a single line that contains the mathematical expression as a string. The expression may contain spaces.
outputFormat
Output a single integer which is the result of evaluating the expression.
## sample3+5
8
</p>