## LCC '18 Contest 1 J3 - Operator Simulation

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Augustus 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 $$3$$ primary binary operators are the or (|), and (&), and xor (^) operators.

#### Operator Details

The or operator will output $$1$$ if either inputs are $$1$$, and $$0$$ otherwise.

• 1 | 1 = 1
• 0 | 1 = 1
• 1 | 0 = 1
• 0 | 0 = 0

The and operator will output $$1$$ if both inputs are $$1$$, and $$0$$ otherwise.

• 1 & 1 = 1
• 0 & 1 = 0
• 1 & 0 = 0
• 0 & 0 = 0

The xor operator will output $$1$$ if exactly one of the inputs is $$1$$, and $$0$$ otherwise.

• 1 ^ 1 = 0
• 0 ^ 1 = 1
• 1 ^ 0 = 1
• 0 ^ 0 = 0

Help Augustus check his answers by simulating these operators on some numbers!

#### Input Specification

The first line will contain the integer $$N\ (1 \le N \le 100)$$, the length of each number in binary.

The second line will contain the first number in binary, $$a$$, the operator to simulate, $$o$$, and the second number in binary, $$b$$, separated by spaces.

• If $$o$$ is |, you must simulate the or operator.
• If $$o$$ is &, you must simulate the and operator.
• If $$o$$ is ^, you must simulate the xor operator.

It is guaranteed both $$a$$ and $$b$$ will be of length $$N$$.

#### Output Specification

Output the resultant number in binary after the performing the specified operation $$o$$ on $$a$$ and $$b$$.

5
10111 & 11100

10100

6
101111 ^ 110011

011100