#C14361. Expression Evaluator
Expression Evaluator
Expression Evaluator
You are given a string that represents a mathematical expression. The expression may contain integers or floating‐point numbers, the arithmetic operators +
, -
, *
, /
, the exponentiation operator **
, and parentheses (
and )
. Your task is to evaluate the expression and print the result.
If the expression is evaluated successfully, print the result. If a division by zero occurs, print the error message Error: Division by zero.
. For any other invalid input, print Error: Invalid input.
.
The evaluation should follow the standard operator precedence rules. In mathematical notation, the exponentiation operator is given by \( a^{b} \) (i.e. a ** b
in the input).
inputFormat
The input consists of a single line from stdin containing a mathematical expression. The expression may include numbers, operators +
, -
, *
, /
, **
and parentheses. Extra spaces may appear between tokens.
outputFormat
Output to stdout the evaluated result. If the expression is invalid or if a division by zero occurs, output the corresponding error message:
Error: Division by zero.
Error: Invalid input.
If the result is an integer, print it without a decimal point; otherwise, print the floating‐point result.
## sample3 + 5 * 2
13
</p>