#C13766. Arithmetic Expression Evaluator

    ID: 43340 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluator

Arithmetic Expression Evaluator

You are given a string representing an arithmetic expression. The expression contains non-negative integers, the operators \( + \), \( - \), \( * \), \( / \) and parentheses. You need to evaluate the expression, taking into account the usual operator precedence and associativity. Note that the division operator \( / \) should perform floating-point division.

If the result is a whole number, output it as an integer; otherwise, output the floating point value.

Examples:

  • Input: 3 + 2 — Output: 5
  • Input: 20 / 4 — Output: 5.0
  • Input: (1 + 2) * 3 — Output: 9

inputFormat

The input consists of a single line containing an arithmetic expression. The expression may include spaces, non-negative integers, operators (+, -, *, /) and parentheses.

outputFormat

Print the result of evaluating the expression. If the result is an integer, output it without a decimal point; otherwise, output the floating-point number.

## sample
3 + 2
5