-
Notifications
You must be signed in to change notification settings - Fork 4
/
101Pattern.cpp
51 lines (47 loc) · 1.06 KB
/
101Pattern.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
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false)
#define lli unsigned long long int
#define pii pair<lli, int>
int main()
{
fast_cin();
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
bool penDown = false;
int ptr1 = 0;
int ptr2 = 0;
int l = s.size();
int count = 0;
while(ptr2<l)
{
if(s[ptr2] == '1' and penDown == false)
{
penDown = true;
ptr1 = ptr2;
}
else if(s[ptr2] == '1' and penDown == true)
{
if(ptr2 - ptr1>1)
{
count++;
}
ptr1 = ptr2;
}
else if(s[ptr2]!='0' and penDown)
{
penDown = false;
}
ptr2 ++;
}
cout<<count<<endl;
}
return 0;
}