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.
10098 - Generating Fast
Moderator: Board moderators
Re: 10098 why getting RE??
Don't double post
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 10098 why getting RE??
You must increase array limit
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
It must be
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.
Code: Select all
string str[10000],s,q,r;
Change it to
Code: Select all
string str[362880],s,q,r;
Change thisA blank line should follow each output set.
Code: Select all
if(i!=a-1)
cout<<endl;
Code: Select all
cout<<endl;
Don't forget to remove your code after getting accepted.

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman