#C14525. Basic Calculator

    ID: 44184 Type: Default 1000ms 256MiB

Basic Calculator

Basic Calculator

This problem requires you to implement a basic calculator that can perform four fundamental arithmetic operations: addition, subtraction, multiplication, and division. The operations are defined as follows:

  • Addition: \(a + b\)
  • Subtraction: \(a - b\)
  • Multiplication: \(a \times b\)
  • Division: \(a / b\), with the restriction that division by zero is not permitted.

You will read a single line from standard input consisting of two operands and an operator, separated by spaces. Your program must parse the operands (which may be integers or decimals) and apply the operation specified by the operator. If an operand cannot be parsed as a number, or if the operator is invalid (i.e., not one of '+', '-', '*', '/'), or if a division by zero is attempted, your program should output the exact error message as specified.

inputFormat

A single line containing two operands and an operator separated by spaces. For example: 2 3 +.

outputFormat

Output a single number which is the result of the operation. In case of an error, output the corresponding error message exactly. The error messages are:

  • Operands must be numeric.
  • Invalid operator. Must be one of '+', '-', '*', or '/'.
  • Cannot divide by zero.
## sample
2 3 +
5.0