-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswapanddelete.cpp
More file actions
64 lines (53 loc) · 1.21 KB
/
swapanddelete.cpp
File metadata and controls
64 lines (53 loc) · 1.21 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll t;
cin>>t;
while(t--){
string s;
cin>>s;
ll n=s.size();
ll c1=0,c2=0;
for( ll i=0; i<n; i++){
if(s[i]=='0'){
c1++;
}
else{
c2++;
}
}
// if(c1==c2) {
// cout<<0<<endl;
// continue;
// }
ll tt=0;
ll i;
for(i=0;i<n; i++){
if(s[i]=='0') {
if(c2>0){ c2--; tt++;}
else break;
}
else if(s[i]=='1'){
if(c1>0){ c1--; tt++;}
else break;
}
}
// if(c2>0){
// for(ll j=i; j<n; j++){
// if(s[j]=='0' && c2>0) {
// tt++;
// c2--;
// }
// }}
// else if(c1>0){
// for(ll j=i; j<n; j++){
// if(s[j]=='1' && c1>0){
// tt++;
// c1--;
// }
// }
// }
cout<<s.size()-tt<<endl;
}
}