#K42657. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a non-empty string that represents a mathematical expression. The expression may contain non-negative integers or floating point numbers and the binary operators +, -, * and /. Your task is to evaluate the expression and output the result as a floating point number.
The expression respects the usual operator precedence, meaning that multiplication and division are evaluated before addition and subtraction. There are no parentheses in the expression.
For example, the expression 3 + 5 / 2
should be evaluated as:
\(3 + \frac{5}{2} = 5.5\)
and the expression 10 - 3 * 2
should be evaluated as:
\(10 - (3 \times 2) = 4.0\)
inputFormat
The input consists of a single line provided via stdin
that contains a valid mathematical expression string. The expression may include spaces which should be ignored.
outputFormat
Output the result of evaluating the expression as a floating point number to stdout
. The answer should be printed without any additional formatting or spaces.
3+5
8.0