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