can someone please help me with the logic of 556A — Case of the Zeros and Ones.

Revision en2, by zonedout, 2024-09-17 21:09:30

556A - Case of the Zeros and Ones

this is my code:

include <bits/stdc++.h>

using namespace std; int main() { string str; int m,i; cin>>m>>str; int l=str.length(); for(i=0;i<l-1;i++) { if(str[i]=='0' && str[i+1]=='1') { str=str.erase(i,i+1); m=m-2; l=l-2; if(i>0) i=i-2; else i=i-1; } else if(str[i]=='1' && str[i+1]=='0') { str=str.erase(i,i+1); m=m-2; l=l-2; if(i>0) i=i-2; else i=i-1; } } cout<<m; }

it fails on test 12. the input is not totally visible since its a long no. the output to test 12 should have been 0(according to the site) but am getting the output as 199996

Tags 900

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English zonedout 2024-09-17 21:11:16 657
en2 English zonedout 2024-09-17 21:09:30 4 Tiny change: ' code:\n\n#inclu' -> ' code:\n\n\n#inclu'
en1 English zonedout 2024-09-17 21:08:53 947 Initial revision (published)