year, Mike found two binary integers and of length (both of them are written only by digits and ) that can have leading zeroes. In order not to forget them, he wanted to construct integer in the following way:
- he creates an integer as a result of bitwise summing of and without transferring carry, so may have one or more -s. For example, the result of bitwise summing of and is or the sum of and is ;
- after that Mike replaces equal consecutive digits in by one digit, thus getting . In the cases above after this operation, becomes and becomes (so, won't have equal consecutive digits).
Unfortunately, Mike lost integer before he could calculate himself. Now, to cheer him up, you want to find any binary integer of length such that will be maximum possible as integer.
Maximum possible as integer means that , , and so on.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains the integer () — the length of and .
The second line of each test case contains binary integer of length . The integer consists only of digits and .
It is guaranteed that the total sum of over all test cases doesn't exceed .
For each test case output one binary integer of length . Note, that or may have leading zeroes but must have the same length .
5 1 0 3 011 3 110 6 111000 6 001011
1 110 100 101101 101110
In the first test case, and choosing gives as a result.
In the second test case, so:
- if you choose , will be equal to , so ;
- if you choose , will be equal to , so ;
- if you choose , you'll get .
- If you select , you'll get .
In the third test case, . If you choose , you'll get and it's the maximum possible .
In the fourth test case, . If you choose , you'll get and it's maximum possible .
In the fifth test case, . If you choose , you'll get and it's maximum possible .
SOLUTION:
Basically we'll check for each bits by doing it's sum with the bits of b if it hold the equality with the pervious sum bits then just put the 0 in string else keep same :)
- #include<bits/stdc++.h>
- using namespace std;
- void run() {
- int N;
- string B;
- cin >> N >> B;
- string A(N, '?');
- A[0] = '1';
- for (int i = 1; i < N; i++) {
- A[i] = '1';
- if (A[i] + B[i] == A[i - 1] + B[i - 1])
- A[i] = '0';
- }
- cout << A << '\n';
- }
- int main() {
- int tests;
- cin >> tests;
- while (tests--)
- run();
- }
0 Comments