-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUgu.cpp
More file actions
48 lines (47 loc) · 876 Bytes
/
Copy pathUgu.cpp
File metadata and controls
48 lines (47 loc) · 876 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
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string str;
cin>>str;
int cnt=0;
int f=0;
if(n==1)
{
cout<<0<<endl;
}
else{
for(int i=0;i<n-1;i++)
{
// if(i==n-1)
// {
// cnt++;
// }
if(str[i]=='1'&& str[i+1]=='0')
{
cnt++;
f++;
}
else if(str[i]=='0' && str[i+1]=='1' && f)
{
cnt++;
}
}
// if(str[0]=='0')
// {
// cout<<cnt-2<<endl;
// }
// else
// {
// cout<<cnt-1<<endl;
// }
cout<<cnt<<endl;
}
}
}