-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherasingzeroes.cpp
More file actions
53 lines (51 loc) · 866 Bytes
/
erasingzeroes.cpp
File metadata and controls
53 lines (51 loc) · 866 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
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
// https://codeforces.com/contest/1303/problem/A
typedef long long ll;
ll remZero(string s)
{
if(s.length()<=2)
{
return 0;
}
int last1=-1,last0=-1;
ll count=0,noof0=0;
bool enc1=false;
for(int i=0;i<s.length();i++)
{
if(s[i]=='1')
{
last1=i;
}
else if(s[i]=='0')
{
last0=i;
}
if(s[i]=='1' && enc1==false)
{
enc1=true;
}
if(s[i]=='0' && enc1==true)
{
noof0++;
}
if(s[i]=='1' && enc1==true)
{
count+=noof0;
noof0=0;
}
}
return count;
}
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout<<remZero(s)<<endl;
}
return 0;
}