Logic Operators (APCS 2017-10 Beginner)
Points 100 1.0s 256MSu is learning three logic operators: AND, OR, and XOR. All three are binary operators, meaning each operation takes two operands, e.g. a AND b. For integers \(a\) and \(b\), the results of the three binary operators are defined by the following three tables:
| a AND b | \(b = 0\) | \(b \ne 0\) |
|---|---|---|
| \(a = 0\) | \(0\) | \(0\) |
| \(a \ne 0\) | \(0\) | \(1\) |
| a OR b | \(b = 0\) | \(b \ne 0\) |
|---|---|---|
| \(a = 0\) | \(0\) | \(1\) |
| \(a \ne 0\) | \(1\) | \(1\) |
| a XOR b | \(b = 0\) | \(b \ne 0\) |
|---|---|---|
| \(a = 0\) | \(0\) | \(1\) |
| \(a \ne 0\) | \(1\) | \(0\) |
For example:
- The result of 0 AND 0 is \(0\); the results of 0 OR 0 and 0 XOR 0 are also \(0\).
- The result of 0 AND 3 is \(0\); the results of 0 OR 3 and 0 XOR 3 are \(1\).
- The result of 4 AND 9 is \(1\); the result of 4 OR 9 is also \(1\), but the result of 4 XOR 9 is \(0\).
Write a program that reads \(a\), \(b\), and the result of a logic operation, and outputs which operations could have produced that result.
Input
The input is a single line containing three integers separated by single spaces. The first integer is \(a\) and the second is \(b\); both are non-negative integers. The third integer is the result of the logic operation, which is always \(0\) or \(1\).
Constraints:
- \(0 \le a, b < 10000\)
- The given result is always \(0\) or \(1\)
Output
Output the operations that could produce the given result. If there are multiple, output them in the order AND, OR, XOR, each on its own line, each line ending with a newline. If no operation can produce the given result, output IMPOSSIBLE. (Note that all letters in the output are uppercase.)
Scoring
The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass. The subtasks are:
- Subtask 1 (\(80\) points): \(a\) and \(b\) are each either \(0\) or \(1\).
- Subtask 2 (\(20\) points): \(0 \le a, b < 10000\).
Sample Input 1
0 0 0
Sample Output 1
AND
OR
XOR
Sample Input 2
1 1 1
Sample Output 2
AND
OR
Sample Input 3
3 0 1
Sample Output 3
OR
XOR
Sample Input 4
0 0 1
Sample Output 4
IMPOSSIBLE
Source
APCS programming exam, October 28, 2017, Problem 1.
Log in to write and submit code.
Log in