LCC '18 Contest 1 J3 - Operator Simulation
View as PDFAugustus is doing his binary math homework. He is not sure that his answers are correct, so he wants to check his answers with you.
Recall that the primary binary operators are the
or (|), and (&), and xor (^) operators.
Operator Details
The or operator will output if either inputs are
, and
otherwise.
1 | 1 = 10 | 1 = 11 | 0 = 10 | 0 = 0
The and operator will output if both inputs are
, and
otherwise.
1 & 1 = 10 & 1 = 01 & 0 = 00 & 0 = 0
The xor operator will output if exactly one of the inputs is
, and
otherwise.
1 ^ 1 = 00 ^ 1 = 11 ^ 0 = 10 ^ 0 = 0
Help Augustus check his answers by simulating these operators on some numbers!
Input Specification
The first line will contain the integer
, the length of each number in binary.
The second line will contain the first number in binary, , the operator to simulate,
, and the second number in binary,
, separated by spaces.
- If
is
|, you must simulate theoroperator. - If
is
&, you must simulate theandoperator. - If
is
^, you must simulate thexoroperator.
It is guaranteed both and
will be of length
.
Output Specification
Output the resultant number in binary after the performing the specified operation on
and
.
Sample Input 1
5
10111 & 11100
Sample Output 1
10100
Sample Input 2
6
101111 ^ 110011
Sample Output 2
011100
Comments