Teaching binary to a child
All submissions for this problem are available.
Da Vinci was once wandering on the roads of Florence when he found a child playing with a
binary string L. He was delighted to see that a small child was showing interest in the beautiful
world of binary strings. To further interest the child and to make sure that the child keeps on
playing with binary strings, he gave the child a task:
Each day the child has to now play with the binary string that comes lexicographically after
the string that he was playing with on the previous day.
He promised the child that whenever he visits back, he will ask him the string that he should
be playing with. If the child gets the correct string, he will recieve a reward from Da Vinci, and
may be Da Vinci will take him as his student.
Help the child to find what string he should be playing with on the day Da Vinci visits him back.
- First line contains T, the number of testcases. It is followed by 2T lines, 2 lines per testcase.
- First line of each testcase starts with a binary string L. Second line contains a single integer K, number of days after which Da Vinci visits the child. The binary string has no leading zeroes, e.g., 0111 has a 0 in the leading (first) position, and such strings will not be there in the input.
- For each testcase, output one line containing the required answer. The output string should not have leading zeroes.
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000
- 1 ≤ K ≤ 1018
Input: 2 1001 1 1000 3 Output: 1010 1011
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.