#K59942. Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
You are given a string representing an arithmetic expression which may include non-negative integers, the operators +
, -
, *
, /
, and parentheses ( )
. Your task is to evaluate the expression following the standard operator precedence rules and output the result as a float.
The precedence rules are as follows:
- Parentheses have the highest precedence.
- Multiplication and division have higher precedence than addition and subtraction.
- Operators with the same precedence are evaluated from left to right.
In mathematical notation, if you denote the expression by \(E\), you are to compute \(result = E\) following the precedence rules. For instance:
\(100 \times (2 + 12) \div 14 = 100.0\)
inputFormat
The input consists of a single line containing the arithmetic expression as a string.
Example:
100 * (2 + 12) / 14
outputFormat
The output should be a single line containing the evaluated result as a float.
Example:
100.0## sample
3 + 5
8.0
</p>