#B2052. Simple Calculator

    ID: 11134 Type: Default 1000ms 256MiB

Simple Calculator

Simple Calculator

This problem requires you to implement a basic calculator that supports the four arithmetic operations: addition, subtraction, multiplication, and division. The input consists of two integers and an operator between them (separated by spaces). The calculations are performed on integers only, and the results will not exceed the range of a standard int type.

Note the following special cases:

  • If a division by zero occurs (i.e. the divisor is 0), output: Divided by zero!.
  • If the operator is not one of the valid operators (+, -, *, /), output: Invalid operator!.
  • For division, perform integer division with truncation toward 0. In mathematical terms, for operands \(a\) and \(b\) (with \(b \neq 0\)), compute \(\text{trunc}(\frac{a}{b})\).

inputFormat

The input is given in a single line containing two integers and an operator, separated by spaces. For example: 3 + 4.

outputFormat

Output a single line containing the result of the calculation. If a division by zero occurs or an invalid operator is provided, output the corresponding error message exactly as specified.

sample

3 + 4
7