You are given three integers a, b and . Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x positions i (1≤i<n) such that si≠si+1. It is guaranteed that the answer always exists.
Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.
Input
The first line of the input contains three integers a, b and x(1≤a,b≤100,1≤x<a+b).
Output
Print only one string s, where s is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.
Examples
input
2 2 1
output
1100
input
3 3 3
output
101100
input
5 3 6
output
01010100
Note
All possible answers for the first example:
1100;
0011.
All possible answers for the second example:
yep, I basically had same strategy as Repeater. Do the "flips" first. My eventual output began with 0.
1. check if "flips" is odd
2. populate stream (or string buffer) with alternating 1 and 0 while decrementing flips and appropriately decrementing ones and zeroes
3a. if odd flips, append remaining 1's to stream. Output remaining 0's.
3b. else Output remaining 0's and Output remaining 1's.
4. Output stream.
Codechef or Hackerrank? having trouble googling to try my solution ;D
Edit: after some more thought, I probably don't need to care about odd or even -- could just forget about appending the 1's at the end and instead just insert immediately after the remaining 0's every time.
can i haz problem link pl0x? those sites seem to not have a search function...
Indeed. Just make a string of all the zeros, or all the ones, whichever you need more of, and then just start inserting the opposite between them until you've got all the flips you need. Any leftover zeros or ones can be easily inserted where they don't affect the flips.