#C3389. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string expr representing a mathematical expression. This expression contains non-negative integers, plus signs (+), minus signs (-), and parentheses.
Your task is to evaluate the expression and output its numerical result.
The expression should be evaluated according to the standard rules of arithmetic: parentheses first, then left-to-right evaluation for + and - operators. All numbers in the expression are non-negative integers and may have multiple digits. Note that the expression may include spaces.
For example, given the expression: 6 - (4 - (2 + 3))
, the evaluation should return 7
.
inputFormat
The input consists of a single line containing the expression expr
. The expression may contain spaces, digits, '+', '-', and parentheses '('.
outputFormat
Output a single integer which is the result of evaluating the expression.
## sample1 + 2
3