#P2104. Basic Binary Operations on Huge Binary Numbers
Basic Binary Operations on Huge Binary Numbers
Basic Binary Operations on Huge Binary Numbers
In this problem, you are given a huge binary number and an operation code representing one of the following operations:
- Operation 1: Add 1 to the entire binary number, i.e. \(x = x + 1\).
- Operation 2: Subtract 1 from the entire binary number, i.e. \(x = x - 1\).
- Operation 3: Multiply the entire binary number by 2, i.e. \(x = x \times 2\).
- Operation 4: Perform integer division of the entire binary number by 2 (floor division), i.e. \(x = \lfloor x/2 \rfloor\).
Note: To simplify the problem, it is guaranteed that the addition and subtraction operations will not result in a carry (or borrow) that changes the highest bit.
inputFormat
The input consists of two tokens separated by whitespace:
- An integer \(op\) (1, 2, 3, or 4) indicating the operation.
- A string \(s\) representing the huge binary number.
For example:
1 1010
outputFormat
Output the resulting binary number after applying the specified operation. The result should be printed as a binary string without extra leading zeros (except when the result is exactly 0).
sample
1 1010
1011