-
Notifications
You must be signed in to change notification settings - Fork 985
/
Copy pathOne Zero Swaps.cpp
65 lines (57 loc) · 1.29 KB
/
One Zero Swaps.cpp
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
/*
Problem Link: https://www.codechef.com/LTIME91B/problems/SWAP10HG
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
int one1=count(s1.begin(),s1.end(),'1');
int zero1=count(s1.begin(),s1.end(),'0');
int one2=count(s2.begin(),s2.end(),'1');
int zero2=count(s2.begin(),s2.end(),'0');
int p=1,cnt=0;
if(one1==one2 && zero1==zero2)
{
// cout<<"*"<<endl;
for(int i=0; i<n; i++)
{
if(s1[i]!=s2[i])
{
if(s1[i]=='0')
{
cnt--;
if(cnt<0)
{
p=0;
break;
}
}
else
{
cnt++;
}
}
}
}
else
{
p=0;
}
if(p==0)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
}
}