My issue
My approach regarding the question Stamps 100 (Starter 100 Q4 Div.4) is to first get the position of 1(first occurrence) and then whole string of 0. And finally putting 1 at the position of its first occurrence. Sample test cases gets passed but when I submit it’s wrong I tried manually many cases and the code is giving the result. Is there any corner case (in case you find my approach is right) or I should do it with some other approach. Below is the code:
My code
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int pos = 0;
while(s[pos]!='1'){
pos++;
}
for(int i=0; s[i]!='\0'; i++){
s[i] = '0';
}
s[pos]='1';
cout<<s<<endl;
}
return 0;
}
Problem Link: S100 Problem - CodeChef