题意:输入a,b,x,要构造出一个一个01串,有a个0,b个1,01或者10,有x个。
题解:构造 从不擅长构造,所以看别人思路,第二天做,不是比赛ac的...
c++:
#include<bits/stdc++.h>
using namespace std;
int a,b,x,c;
int main()
{
cin>>a>>b>>x;
if(a>=b)c=0;
else c=1;
while(x>1)
{
cout<<c;
if(c) b--;
else a--;
c=1-c,x--;
}
if (c)
{
for(int i=0; i<b; i++)
cout<<1;
for(int j=0; j<a; j++)
cout<<0;
}
else
{
for(int i=0; i<a; i++)
cout<<0;
for(int j=0; j<b; j++)
cout<<1;
}
return 0;
}
python:
a,b,x=map(int,input().split())
s=""
if a>=b:c=0
else:c=1
while x>1:
s+=str(c)
if c==0:a-=1
else:b-=1
c=1-c;x-=1
if c==0:s+=a*"0"+b*"1"
else:s+=b*"1"+a*"0"