You are given three integers aa, bb and xx. Your task is to construct a binary string ss of length n=a+bn=a+bsuch that there are exactly aa zeroes, exactly bb ones and exactly xx indices ii (where 1≤i<n1≤i<n) such that si≠si+1si≠si+1. It is guaranteed that the answer always exists.
For example, for the string "01010" there are four indices ii such that 1≤i<n1≤i<n and si≠si+1si≠si+1 (i=1,2,3,4i=1,2,3,4). For the string "111001" there are two such indices ii (i=3,5i=3,5).
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 aa, bb and xx (1≤a,b≤100,1≤x<a+b)1≤a,b≤100,1≤x<a+b).
Output
Print only one string ss, where ss 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
题解:做的时候疯狂wa7(1 100 2),最后发现水过一组a<b就没考虑了,太菜了!
代码如下:
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 1007
#define N 100005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define Debug(x) cout<<x<<" "<<endl
using namespace std;
typedef long long ll;
int main()
{
int a,b,x;
cin>>a>>b>>x;
if(a>=b)
{
if(x%2==0)
{
for(int i=0; i<a-x/2; i++)
printf("0");
for(int i=0; i<x-1; i++)
if(i%2!=0)
printf("0");
else
printf("1");
for(int i=x/2; i<b; i++)
printf("1");
printf("0");
}
else
{
for(int i=0; i<a-x/2; i++)
printf("0");
for(int i=0; i<x; i++)
{
if(i%2==0)
printf("1");
else
printf("0");
}
for(int i=x/2+1; i<b; i++)
printf("1");
}
}
else
{
swap(a,b);
if(x%2==0)
{
for(int i=0; i<a-x/2; i++)
printf("1");
for(int i=0; i<x-1; i++)
if(i%2!=0)
printf("1");
else
printf("0");
for(int i=x/2; i<b; i++)
printf("0");
printf("1");
}
else
{
for(int i=0; i<a-x/2; i++)
printf("1");
for(int i=0; i<x; i++)
{
if(i%2==0)
printf("0");
else
printf("1");
}
for(int i=x/2+1; i<b; i++)
printf("0");
}
}
return 0;
}
上面代码a,b讨论后输出过程是一样的,可以变为如下程序:
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 1007
#define N 100005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define Debug(x) cout<<x<<" "<<endl
using namespace std;
typedef long long ll;
int main()
{
int a,b,x,n;
char u,v;
cin>>a>>b>>x;
n=a+b;
if(a>b) u='0',v='1';
else
{
u='1',v='0';
swap(a,b);
}
for(int i=0; i<x/2; i++)
{
cout<<u<<v;
a--,b--;
}
if(x%2==0)
{
while(b--)
cout<<v;
while(a--)
cout<<u;
}
else
{
while(a--)
cout<<u;
while(b--)
cout<<v;
}
return 0;
}