#CCBCHMUOI0000028. Máy tính chia lấy dư (Integer Calculator with Remainder)
Máy tính chia lấy dư (Integer Calculator with Remainder)
Integer Calculator with Remainder
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers a and b and an operator op, compute addition, subtraction, multiplication, integer division or remainder for +, -, *, / or %. C integer division truncates toward zero and its remainder satisfies a = (a/b)*b + a%b. For / or % with b = 0, print DIV0; for other operators print INVALID.
Input
One line contains integers a, b, followed by one operator character op, in that order.
Output
Print the integer result, or DIV0 for zero divisor with / or %, or INVALID for an unsupported operator.
Subtasks
- Subtask 1 (20%): 0 <= a,b <= 20 and op is + or -.
- Subtask 2 (30%): -100 <= a,b <= 100 and op is one of +, -, *, / or %.
- Subtask 3 (50%): -10^6 <= a,b <= 10^6 and op is one non-whitespace ASCII character.
Examples
Example 1
Input
-7 3 %
Output
-1
Explanation
C truncates -7/3 to -2, giving remainder -1.
Example 2
Input
12 0 /
Output
DIV0
Explanation
Since division by zero is invalid, print DIV0.