Can anyone see whats wrong with this code, it is saying wrong answer

#include
using namespace std;

int main()
{
int N, T, i, count;
cin >> T;
while (T–)
{
cin >> N;
char S[N];
cin >> S;
count = 0;
for (i = 0; i < N; i++)
{
if (S[i] == ‘0’)
{
if ((S[i - 1] == ‘0’ && S[i + 1] == ‘0’) || (S[i - 1] == ‘0’ && i == N - 1) || (S[i + 1] == ‘0’ && i == 0))
count++;
}
}
cout << count<<"\n";
}
return 0;
}

Perhaps you should mention the question link so that we can know what is it you are trying to do

2 Likes

Just check datype error

Use string instead of array of chars

Also for i = 0 , i-1 is not defined.

1 Like

There are many problems with this code:-

  1. no exit specified for while loop
  2. dynamic char array is not possible in c++
  3. ASCII character used for ’ ’ you used are incorrect as per compiler because you have used improper ’ ’ used in your code(try checking your code in turbo c++).
  4. i-1 of array index is arrayindexoutofbound .
  5. lastly it’s a random code , so the outcomes are not predictable hence waste code.

Its running purely right, and also its not random code…you see…
Problem - Little Elephant and Bombs (LEBOMBS) @ codechef

Problem - Little Elephant and Bombs (LEBOMBS) @ codechef