-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwtch.cpp
53 lines (53 loc) · 853 Bytes
/
wtch.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
#include<bits/stdc++.h>
main()
{
int t;
scanf("%d",&t);
while(t--)
{
int c=0,n,i,count=0;
scanf("%d",&n);
char str[n+1];
scanf("%s",str);
for(i=0;i<n;i++)
{
if(str[i]=='0')
c++;
}
if(c==n&&n%2==0)
printf("%d\n",n/2);
else if(c==n&&n%2!=0)
printf("%d\n",(n+1)/2);
else
{
for(i=0;i<n;i++)
{
if(i==0)
{
if(str[i]=='0'&&str[i+1]=='0')
{
count++;
str[i]='1';
}
}
else if(i>0&&i<n-1)
{
if(str[i]=='0'&&str[i+1]=='0'&&str[i-1]=='0')
{
count++;
str[i]='1';
}
}
else
{
if(str[i]=='0'&&str[i-1]=='0')
{
count++;
str[i]='1';
}
}
}
printf("%d\n",count);
}
}
}