#C10501. Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
Arithmetic Expression Evaluation
Given a mathematical expression as a string containing non-negative integers, the operators +, -, *, and /, and parentheses ()
to override the default precedence, you are required to evaluate the expression and output the result as an integer. Note that division should truncate towards zero.
For example:
3+5*2
evaluates to 13(2+3)*(5-2)
evaluates to 1520/(4+1)
evaluates to 442
evaluates to 42
Your task is to implement this evaluation considering the standard arithmetic precedence rules: multiplication and division have higher precedence than addition and subtraction. Parentheses can override these rules. All intermediate calculations use integer arithmetic.
inputFormat
A single line string representing a valid mathematical expression. The expression can include numbers, the operators +, -, *, /, and parentheses.
outputFormat
An integer representing the result after evaluating the expression. Division results should be truncated towards zero.## sample
3+5*2
13