Page 5 of 5

10098 why getting RE??

Posted: Thu Jul 24, 2014 9:15 am
by sajal2k8
Here is my code:
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
int a,b=0,c;
string str[10000],s,q,r;
char ch;
cin>>a;
for(int i=0;i<a;i++)
{
cin>>s;
for(int k=0;k<s.length()-1;k++)
{
for(int l=k+1;l<s.length();l++)
{
if(s[k]>s[l])
{
ch=s[l];
s[l]=s[k];
s[k]=ch;
}
}
}
do
{

str=s;
b++;

}while(std::next_permutation(s.begin(),s.end()));
sort(str,str+b);
for(int j=0;j<b;j++)
{
cout<<str[j]<<endl;
}
if(i!=a-1)
cout<<endl;
b=0;
}
return 0;
}
I am getting runtime error. Please help. Thank You in advance.

Re: 10098 why getting RE??

Posted: Thu Jul 24, 2014 2:01 pm
by lighted
Don't double post

Re: 10098 why getting RE??

Posted: Thu Jul 24, 2014 2:04 pm
by lighted
You must increase array limit

Code: Select all

string str[10000],s,q,r;
It must be at least 10! = 3628800. But i checked that 362880 (9!) is enough. Maybe judge input contains strings with length < 10.

Change it to

Code: Select all

string str[362880],s,q,r;
A blank line should follow each output set.
Change this

Code: Select all

if(i!=a-1)
 cout<<endl;
It must be

Code: Select all

cout<<endl;
And you don't need to sort permutations. It will be generated in ascending sorted order.

Don't forget to remove your code after getting accepted. 8)