#K56247. Arithmetic Expression Evaluator

    ID: 30156 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluator

Arithmetic Expression Evaluator

You are given a string representing an arithmetic expression. The expression may contain positive numbers (which can be floating point numbers), the operators +, -, *, /, and parentheses ( and ). Your task is to evaluate the expression and output the result as a floating point number.

The evaluation should follow the usual operator precedence rules:

  • Addition and subtraction have lower precedence.
  • Multiplication and division have higher precedence.
  • Parentheses ( ... ) can override normal precedence.

All operations are binary and left-associative. Use the following operator precedence in your evaluation: \( \mbox{precedence}(+)=\mbox{precedence}(-)=1, \quad \mbox{precedence}(*)=\mbox{precedence}(/)=2. \)

You need to read the input from standard input (stdin) and write your answer to standard output (stdout).

inputFormat

The input consists of a single line containing a valid arithmetic expression. The tokens may be separated by spaces.

outputFormat

Output a single line containing the evaluated result of the arithmetic expression as a floating point number.

## sample
3 + 5 * 2 - ( 12 / 4 )
10.0