[problem:556A]↵
↵
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;HERE is my code:↵
↵
}↵
↵
↵
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
↵
↵
↵
#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