My issue
whats wrong with this code
My approach is, find the first occurance of 1.
now change all the 1 to 0 from the first occurance of 1.
include
using namespace std;
int main() {
int test;
cin>>test;
while(test–){
int x;
cin>>x;
string s;
cin>>s;
bool y=true;
string ans=“”;
for(int i=0;i<x-2;i++){
if(s.at(i)==‘1’&&y){
ans+=“1”;
y=false;
}
else
ans+=“0”;
}
ans+=“00”;
cout<<ans<<endl;
}
return 0;
}
My code
#include <iostream>
using namespace std;
int main() {
int test;
cin>>test;
while(test--){
int x;
cin>>x;
string s;
cin>>s;
bool y=true;
string ans="";
for(int i=0;i<x-2;i++){
if(s.at(i)=='1'&&y){
ans+="1";
y=false;
}
else
ans+="0";
}
ans+="00";
cout<<ans<<endl;
}
return 0;
}
Problem Link: S100 Problem - CodeChef