-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary-String-Constructing.cpp
More file actions
73 lines (69 loc) · 1.64 KB
/
Binary-String-Constructing.cpp
File metadata and controls
73 lines (69 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a,b,c;
cin>>a>>b>>c;
string s;
char d='1',e='0';
ll count1=0;// for 0s
ll count2=0;// for 1s
if(c==1)
{
for(ll j=0;j<b;j++)
s.push_back(d);
for(ll j=0;j<a;j++)
s.push_back(e);
}
else if(c%2==0 && a==1)
{
s.push_back(d);
s.push_back(e);
count1++;count2++;
for(ll j=0;j<b-count2;j++)
s.push_back(d);
for(ll j=0;j<a-count1;j++)
s.push_back(e);
}
else
{
for(ll i=1;i<c;i++)
{
if(c%2==0)
{
if(i%2==0)
{
s.push_back(d);
count2++;
}
else
{
s.push_back(e);
count1++;
}
}
else
{
if(i%2==0)
{
s.push_back(e);
count1++;
}
else
{
s.push_back(d);
count2++;
}
}
}
for(ll j=0;j<b-count2;j++)
s.push_back(d);
for(ll j=0;j<a-count1;j++)
s.push_back(e);
}
cout<<s<<endl;
return 0;
}