#C11022. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a mathematical expression. The expression can contain non-negative integers and the operators + (addition), - (subtraction), * (multiplication), and / (division). It may also include parentheses ( )
to indicate operation precedence.
Your task is to compute the result of this expression following the standard operator precedence rules. Note that division should be interpreted as integer division (i.e. rounding down the result if necessary, but the given test cases guarantee an integer result).
The mathematical evaluation in terms of formal grammar can be described as follows:
\[ \text{Expression} \;:=\; \text{Term} \; ( (\;+\;|\;-\;)\; \text{Term} )^* \]
\[ \text{Term} \;:=\; \text{Factor} \; ( (\;*\;|\;/\;)\; \text{Factor} )^* \]
\[ \text{Factor} \;:=\; \text{Number} \; | \; ( \text{Expression} ) \]
\[ \text{Number} \;:=\; \text{a sequence of digits}\; \]
inputFormat
The input consists of a single line containing the mathematical expression. The expression is provided without any additional spaces. You can assume the expression is valid and not empty.
outputFormat
Output the result of the evaluation as an integer to the standard output.
## sample2+3
5