#K1691. Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
You are given a string representing a mathematical expression. The expression contains non-negative decimal numbers and the operators +
, -
, *
, and /
. It may also include parentheses (
and )
to override the standard operator precedence rules.
Your task is to evaluate the expression and output the result as a floating-point number.
Note: The expression follows the common arithmetic rules. For example, the expression 3 + 2 * 2 should be evaluated as 3 + (2 * 2) = 7.0.
Mathematical operations are defined as follows:
\(a + b, \quad a - b, \quad a \times b, \quad a \div b\)
inputFormat
The input is provided via stdin as a single line containing the mathematical expression to evaluate. The expression can include spaces, digits, decimal points, operators (+
, -
, *
, /
), and parentheses.
outputFormat
Output the computed result of the expression as a floating-point number on a single line via stdout. For example, if the computed result is 7, you should output 7.0
.
3 + 2 * 2
7.0