Help me in solving ADJFLIP problem

My issue

In my code, 101001 is also converted to 111111. can any one help with the solution then it would be so helpful. And i don’t know stack.
Thank You.

My code

``````#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main() {
int T;
cin>>T;
string v0="0000000000000000000000000";
string v1="1111111111111111111111111";
string input;
int n,one=-1,zero=-1;
for(int i=1; i<=T; i++){
cin>>n;
cin>>input;
v0=(v0.substr(0,n));
v1=(v1.substr(0,n));
for(int i=0; i<=n; i++){

//  if(input[i]=='1'){
//       one++;
//  }
//   else if(input[i]=='0'){
//       zero++;
//   }
// for(int i=0; i<=n; i++)
// if(input==v0){
//     cout<<"YES"<<endl;
//     break;
// }
// if(input==v1){
//     cout<<"YES"<<endl;
//     break;
// }
if(input[i]=='0' && input[i+1]=='1'){
input[i]='1';
input[i+1]='1';
}
if(input[i]=='1' && input[i+1]=='0'){
input[i]='1';
input[i+1]='1';
}
//  if(input[i]=='0' && input[i+1]=='0'){
//      input[i]='1';
//      input[i+1]='1';
//  }
i++;

}
if(input==v1){
cout<<"YES"<<endl;
}
else if(input==v0){
cout<<"YES"<<endl;
}
else {
cout<<"NO"<<endl;
}
// else if(input==v0){
//     cout<<"YES"<<endl;
// }

}

return 0;
}

``````

Problem Link: ADJFLIP Problem - CodeChef

I think question mentions you have to select such indices in which S_i = S_{i+1}. In your code when i=1 you will enter the if statement and input will be converted to 111001 and similarly
i=2 → 111101
i=3 → 111111

Hence you getting that 111111

Hello
Please solve my question

use a stack and check top element of stack and current element of string are same pop it else push current element of string and check stack size is 0 or 1.

Si=Si+1. please explain me this, i’m new to coding and contests. It would be helpful.