-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1913b.cpp
More file actions
43 lines (35 loc) · 847 Bytes
/
1913b.cpp
File metadata and controls
43 lines (35 loc) · 847 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
int main() {
fastio;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
long ans = 0,zeros = 0,ones = 0;
long n = s.size();
for(char c : s){
if(c == '0')zeros++;
else ones++;
}
if(ones == zeros){
cout << 0 << "\n";
}else{
for(int i = 0;i < n;i++){
if(s[i] == '0' && ones > 0){
ones--;
ans++;
}else if(s[i] == '1' && zeros > 0){
zeros--;
ans++;
}else{
break;
}
}
cout << n - ans << "\n";
}
}
return 0;
}