#K2991. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
Given a mathematical expression as a string, evaluate its integer result. The expression contains non-negative integers, the operators +
, -
, *
, /
, and parentheses. The operator precedence is as usual: multiplication and division have higher precedence than addition and subtraction. Division is performed as integer division (i.e. truncated towards zero).
You may assume that the input expression is valid. The evaluation should follow the rules of arithmetic, and parentheses can be used to override the default operator precedence.
For example, using LaTeX to represent the formula, the evaluation of an expression suchn as \(3+2\times2\) is \(7\), and the expression \(\frac{100}{2}\times3+5\) evaluates to \(155\).
inputFormat
The input is a single line that contains a mathematical expression. The expression is a string consisting of digits, operators (+, -, *, /), and parentheses.
outputFormat
The output is a single integer which is the result of evaluating the given expression.
## sample3+2*2
7