#C14885. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string that represents a mathematical expression. The expression can contain integers, the basic operators +, -, *, / and parentheses ( ). You should evaluate the expression obeying the standard operator precedence rules: multiplication and division have higher precedence than addition and subtraction. In particular, use \(\times\)
for multiplication and \(\div\)
for division (performed as floating point division). All spaces in the expression should be ignored.
Example: For the input expression (2 + 3) * 4 - 5 / (1 + 1)
, the expected output is 17.0
.
inputFormat
A single line string from standard input. The string represents a mathematical expression and may include digits, spaces, operators (+, -, *, /) and parentheses. For example: (2 + 3) * 4
outputFormat
Output the evaluated result of the expression to standard output. The result is a number. When division occurs, the output should be in floating point format (e.g., 11.0), otherwise an integer (e.g., 5).## sample
2 + 3
5