#C13882. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a single line of input which is a string representing a mathematical expression. This expression may include positive numbers, the operators +
, -
, *
, /
, and parentheses ( )
to override operator precedence. Note that extra spaces may be present in the input.
Your task is to evaluate the expression following the standard operator precedence rules. If the expression contains a division by zero, output Division by zero encountered in the expression
. If the expression is not valid, output Invalid mathematical expression
.
All formulas or expressions are written in LaTeX format when necessary. For example, an addition operation is represented as \(a+b\) and multiplication as \(a\times b\).
inputFormat
The input is read from standard input (stdin) and consists of a single line containing the mathematical expression to evaluate.
outputFormat
Output the evaluated result to standard output (stdout). If an error occurs (such as division by zero or an invalid expression), output the corresponding error message exactly.
## sample2 + 3
5