#t239. 简单计算器

简单计算器

Simple Calculator

Problem Description

A simplest calculator supporting the four operations  +,−,∗,/ \,+, -, *, /\,. Consider only the case where the input and output are integers, and the data and results do not exceed the range of int.

Input Format

The input is a single line containing three parameters: the 1st and 2nd parameters are integers, and the 3rd parameter is an operator (one of +,−,∗,/+,-,*,/).

Output Format

Output a single line containing one integer: the result of the operation. However:

  1. If the divisor is  0 \,0\,, output: Divided by zero!
  2. If an invalid operator appears (i.e. one not among  +,−,∗,/ \,+, -, *, /\,), output: Invalid operator!

Sample Input

1 2 +

Sample Output

3

Hint

  • The third input is an operator character — read it as a character.
  • Four operations plus two error outputs. The ordering of the error branches matters: when an invalid operator and division by zero appear together, which should be output? Re-read the statement.
  • Integer division is just / (the problem says the output is an integer).

You may consider using if and switch structures.