#C14650. Evaluate Mathematical Expression

    ID: 44323 Type: Default 1000ms 256MiB

Evaluate Mathematical Expression

Evaluate Mathematical Expression

You are given a string representing a mathematical expression. The expression consists of non-negative integers, the operators +, -, *, /, and may include parentheses ( ). The operators follow the usual precedence rules. In particular, the multiplication and division operations have higher precedence than addition and subtraction. You are required to evaluate the expression using a stack-based method. If a division by zero occurs, the program should handle it gracefully by outputting an error message.

Note: Use the following LaTeX formatted formulas for operator precedence if needed:

  • \( * , / \) have higher precedence
  • \( + , - \) have lower precedence

The calculated result should be printed as a floating point number formatted to one decimal place. In case of an attempted division by zero, output exactly Error: division by zero without quotes.

inputFormat

The input is provided via standard input (stdin) and consists of a single line containing a valid mathematical expression. The expression may contain spaces, digits, operators (+, -, *, /) and parentheses.

outputFormat

Print the result of the evaluated expression to standard output (stdout) as a floating point number with one decimal place. If division by zero occurs during the evaluation, print Error: division by zero.

## sample
3+5
8.0