-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinary Cut.cpp
57 lines (49 loc) · 882 Bytes
/
Binary Cut.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
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define S string
#define vi vector<int>
#define V vector
#define usii unordered_set<int,int>
#define umii unordered_map<int,int>
#define um unordered_map
#define us unordered_set
#define bg begin()
#define ed end()
#define pb push_back
#define forloop for(int i=0;i<n;i++)
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
void solve()
{
string str;
cin>>str;
int len=str.length();
int ct1=0,ct0=0;
for(int i=1; i<len; i++)
{
if(str[i-1]=='1'&& str[i]=='0')
ct1++;
if(str[i-1]=='0'&& str[i]=='1')
ct0++;
}
ct1++;
ct0--;
if(ct0<0)
ct0=0;
int ans=ct1+ct0;
if(ans==0)
ans=1;
cout<<ans<<nl;
}
signed main()
{
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}