#C2591. Evaluate Mathematical Expression with Parentheses
Evaluate Mathematical Expression with Parentheses
Evaluate Mathematical Expression with Parentheses
You are given a string representing a mathematical expression that consists of single-digit positive integers, the addition operator (+), the subtraction operator (-), and parentheses. Your task is to evaluate the expression and print the result as an integer.
The evaluation follows standard arithmetic rules. Note that the expression can include nested parentheses. For instance, the expression ( (1+(4+5+2)-3)+(6+8) ) should be evaluated as 23.
Be careful with spaces in the input. You must read the expression from standard input and output the result to standard output.
inputFormat
The input consists of a single line that contains the mathematical expression as a string. The expression may include spaces.
outputFormat
Output a single integer which is the result of evaluating the given expression.## sample
1 + 1
2
</p>