getting runtime error on testcase 11
Exit code is -1073741819
here is my code:
include include<string.h> include
using namespace std; int main() { string lame=""; string a,b="",c=""; int i,j,n; getline(cin,a);
for(i=0;i<a.length();i++)
b[i]=a[i];
sort(a.begin(),a.end());j=0;
for(i=0;i<a.length();i++)
{
if(b[i]!=a[j])
{
lame.push_back(b[i]);
}
else
{
c.push_back(a[j]);
j++;
}
}
if(lame.length()!=0)
{
reverse(lame.begin(),lame.end());
c=c+lame;
}
cout<<c<<endl;
return 0;
}
Auto comment: topic has been updated by blowin_in_the_wind (previous revision, new revision, compare).
You're going out of the bounds for b here. At that moment in time b.length() is 0 so you can't assign b[0], b[1] ... b[a.size()-1] yet. Either use
b += a[i]
instead ofb[i] = a[i]
, or even better, do without the loop completely and just dob = a