-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBinary_String_Constructing.cpp
More file actions
69 lines (67 loc) · 1.06 KB
/
Binary_String_Constructing.cpp
File metadata and controls
69 lines (67 loc) · 1.06 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,x;cin>>a>>b>>x;
int c1[2]={0},c2[2]={0};
string s1="",s2="";
for(int i=0;i<x;i++)
{
if(i%2==0){
s1+='0';c1[0]++;
}
else {
s1+='1';c1[1]++;
}
int j=i;
if(j%2==0)
{
s2+='1';
c2[0]++;
}
else
{
s2+='0';
c2[1]++;
}
}
int a1=a-c1[0];
int b1=b-c1[1];
string dummy="";
if(a1>0)
{
while(a1>0)
{
dummy+='0';
a1--;
}
dummy+=s1;
}
if(b1>0)
{
while(b1>0)
{
dummy+='1';
b1--;
}
}
int a2=a-c2[0];
int b2=b-c2[1];
string yummy="";
while(a2>0)
{
yummy+='0';
a2--;
}
yummy+=s1;
while(b2>0)
{
yummy+='1';
b2--;
}
if(dummy.size()==a+b)
cout<<dummy;
else
cout<<yummy;
return 0;
}