#C14064. Simple Arithmetic Expression Evaluator
Simple Arithmetic Expression Evaluator
Simple Arithmetic Expression Evaluator
This problem requires you to build a simple arithmetic expression evaluator. You are given an expression in the form a op b, where a and b are non-negative numbers (which may be integers or decimals), and op is one of the four basic arithmetic operators: +, -, *, or /.
Your task is to parse the input expression and compute the result. The expression should follow the strict format:
$$a\; op \; b$$
If the expression does not consist of exactly three parts, or if the numbers or operator are invalid, your program should output an appropriate error message as described below.
Error messages:
- Invalid format: When the expression does not consist of exactly three tokens.
- Invalid numbers: When any of the number tokens cannot be parsed as a valid number.
- Invalid operator: When the provided operator is not one of +, -, *, or /.
- Division by zero error: When attempting to divide by zero.
For valid expressions, if the result is an integer (e.g. 20.0), you should output it without a decimal point.
inputFormat
The input consists of a single line, which is a string representing the arithmetic expression. Tokens are separated by whitespace. For example:15 + 5
outputFormat
For valid expressions, output the computed result. If an error is encountered, output one of the following error messages exactly: "Invalid format", "Invalid numbers", "Invalid operator", or "Division by zero error".
## sample15 + 5
20