#C9615. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a mathematical expression that consists of positive integers, the binary operators +
, -
, *
, and /
, and possibly nested parentheses. The expression should be evaluated according to the standard operator precedence rules: multiplication and division have higher precedence than addition and subtraction. All divisions are integer divisions, meaning the result of e.g. $8/4$ is 2
and $2-3/5$ is 2
(since $3/5=0$ in integer division).
For example, the expression $3+5*2$ should be evaluated as $3+(5\times2)=13$, and the expression $100*(2+12)/14$ results in 100
.
Your task is to implement a function that parses and evaluates such expressions correctly.
inputFormat
The input consists of a single line containing the mathematical expression (as a string). The expression will only contain positive integers, the operators +
, -
, *
, /
, and parentheses. There will be no invalid characters.
outputFormat
Output a single integer, which is the evaluation result of the expression.
## sample3+5
8