#K37997. Evaluating Arithmetic Expressions
Evaluating Arithmetic Expressions
Evaluating Arithmetic Expressions
You are given a string expr that represents a valid arithmetic expression containing non-negative integers and the operators \(+\), \(-\), \(\times\), and \(\div\). The expression may also include parentheses \((\) and \()) which change the order of evaluation. The division operator performs integer division (i.e., the result is the quotient of the division with truncation toward zero).
Your task is to evaluate the expression according to the usual operator precedence rules and output the result as an integer.
Note:
- The expression is guaranteed to be valid.
- There will be no unary operators.
For example:
- Input:
3+2*2
→ Output:7
- Input:
(1+(4+5+2)-3)+(6+8)
→ Output:23
- Input:
14-3/2
→ Output:13
inputFormat
The input consists of a single line containing the arithmetic expression expr. The expression may include spaces.
outputFormat
Output a single integer — the result of evaluating the expression.
## sample3+2
5