#K77922. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a mathematical expression. The expression consists of non-negative integers and the operators +, -, *, and /, along with parentheses for grouping. Your task is to evaluate the expression and output the result as a floating point number.
The expression obeys the standard operator precedence rules:
- Addition and subtraction: \(a+b,\ a-b\)
- Multiplication and division: \(a\times b,\ a\div b\)
- Parentheses: \((\,a+b\, )\)
For example:
- Input:
3+2*2
→ Output:7.0
because \(3+2\times2=7.0\) - Input:
(1+(4+5+2)-3)+(6+8)
→ Output:23.0
You must process input from standard input (stdin) and output your answer to standard output (stdout).
inputFormat
The input consists of one single line containing the mathematical expression as a string. The string will include digits (0-9) and the characters '+', '-', '*', '/', and parentheses.
Example:
3+2*2
outputFormat
Output a single floating point number which is the result of evaluating the given expression.
Example:
7.0## sample
3+2
5.0
</p>