10098 - Generating Fast

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

10098 why getting RE??

Post by sajal2k8 » Thu Jul 24, 2014 9:15 am

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.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10098 why getting RE??

Post by lighted » Thu Jul 24, 2014 2:01 pm

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

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10098 why getting RE??

Post by lighted » Thu Jul 24, 2014 2:04 pm

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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 100 (10000-10099)”