I got it…i missed the case when n=1…
Your code fails for this configuration
1
5
10101
can someone…anyone tell me whats wrong in my code…It run perfectly in devC and codeblocks
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n,arr[1000],ct=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
if(i==0 && arr[i+1]==0 && arr[i]==0)
{
ct++;
}
else if(i==n-1 && arr[i-1]==0 && arr[i]==0)
{
ct++;
}
else if( i>0 && arr[i]==0 && arr[i+1]==0 && arr[i-1]==0)
{
ct++;
}
}
if(ct>0)
{
cout<<ct<<endl;
}
else
cout<<0<<endl;
}
// your code goes here
return 0;
}
Please either format your code or link to your submission - the forum software has mangled it and it won’t compile!
you’re so good…thank you so much for replying!!!
Here’s the link of my code…
https://www.codechef.com/viewsolution/28553084
I know
Thanks!
Consider the testcase:
1
6
000110
(the answer should be 2
).
the output is 2:frowning_face:
Based on your screenshot, you’ve added spaces between all the 0’s and 1’s in the testcase I gave you, for some reason.
Oopsi desy…Got it…
I’ll correct my mistake and let you know the output…
Thanks a lot !!!
it run successfully now…without any memory,time limit,or run time errors…PhewwWwww!!!
Thank You !!!
how did your code work for n = 2 cases? wouldn’t count be incremented twice?
Example?
It goes in the bottom part only when n is 1. Otherwise it just does whatever your code does.
say i enter 00, wouldn’t count become 2?
Yes?, it’s supposed to be 2.
forget it . My bad
fixed it and it worked. thanks man