#C13919. Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
You are given a string representing a mathematical expression, which may include addition (+), subtraction (-), multiplication (*), division (/), parentheses, and spaces. Your task is to evaluate the expression and print the result. If the expression is invalid (for example, due to syntax errors, unmatched parentheses or division by zero), output "Invalid expression".
The mathematical operations follow the usual operator precedence rules. All operations are left-associative. The result can be an integer or a decimal number.
Note: Any formulas must be represented in LaTeX format. For example, an expression like \(3+5=8\) or \(\frac{100 \times (2+12)}{14}=100.0\).
inputFormat
The input consists of a single line from the standard input (stdin) containing the mathematical expression as a string. The expression may contain spaces.
outputFormat
Print the evaluated result to standard output (stdout). If the input expression is invalid or cannot be evaluated, output Invalid expression
.
3 + 5
8