Page 1 of 5

10098 - Generating Fast

Posted: Fri Aug 30, 2002 3:31 pm
by rakeb
why Output Limit Exceeded!!!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long len;
char str[11],taken[11],permout[11];
int sfunc(const void *a,const void *b)
{
return (int)(*((char *) a) - *((char *)b));

}
void perm(long lev)
{
long i;
if(lev == len )
{
printf("%s\n",permout);
return;
}
for(i = 0; i < len ; i++)
if(!taken)
{
permout[lev] = str;
taken = 1;
perm(lev + 1);
taken = 0;
}
}
void main()
{
long n;
scanf("%ld",&n);
while(n--)
{
scanf("%s",&str);

len = strlen(str);
qsort(str,len,sizeof(str[0]),sfunc);
perm(0);
printf("\n");

}
}

Posted: Fri Aug 30, 2002 4:05 pm
by abiczo
I think the problem is that there is no \0 at the end of 'permout'.
Before printing it, put a zero character at the end of 'permout' (e.g. permout[len]=0)

RAKEB

Posted: Fri Aug 30, 2002 5:00 pm
by rakeb
thanx for reply

PLZ help

Posted: Fri Aug 30, 2002 5:14 pm
by rakeb
Now i m facing Runtime Error (SIGXFSZ) :o

10098 Generating Fast, Sorted Permutation

Posted: Sat Sep 21, 2002 1:37 pm
by rakeb
Can anybody give me outpus for

2
aABb
aabb

Thanx

not clear - the problem statement

Posted: Sat Sep 21, 2002 11:04 pm
by Shahid
in the problem statement one sentense is :
Not that the strings should be treated, as case sensitive strings and no permutation should be repeated.


is it means that the strings should not be treated as case sensitive strings or it means the opposite?

Posted: Sun Sep 22, 2002 8:45 am
by Picard
this problem is very similar to P195. i think they ment "Note that the...", but it doesn't really matter because in the judge's input there is no upper case letter.
( i used this short program: while ((ch=getchar())!=EOF) if (tolower(ch)!=ch) abort(); )

what tweak it is?

Posted: Mon Sep 23, 2002 8:20 pm
by Shahid
hi picard, is ur short program for cheking the judge input??? if so then gr8... actually i never thought of cheking the judge input f any problem ...

10098

Posted: Wed Apr 02, 2003 11:09 am
by Hisoka
I think is just simple recursion problem, but I always got Output Limit. Can you check my program ?
[c]/* @begin_of_source_code */
#include <stdio.h>
#include <string.h>

int n;
char cek[15],in[15],out[15];

void permutation(int banyak)
{
int i;
if(banyak==n){
out[banyak]=0;
puts(out);
}
else
for(i=0;i<n;i++)
if(cek==0){
cek=1;
out[banyak]=in;
permutation(banyak+1);
out[banyak]=0;
cek=0;
}
}

void main()
{
char temp;
int i,j,banyak;
scanf("%d",&banyak);
while(banyak--){
if(scanf("%s",in)==1){
n=strlen(in);
for(i=0;i<n;i++)
for(j=n-1;j>i;j--)
if(in[j]<in[j-1]){
temp=in[j];
in[j]=in[j-1];
in[j-1]=temp;
}
for(i=0;i<15;i++) cek=0;
permutation(0);
puts("");
}
}
}
/* @end_of_source_code */[/c]

please help me :cry:

THANX......

Posted: Wed Apr 02, 2003 12:40 pm
by kmhasan
Try the following input:

Code: Select all

1
aaaaaaaaaaaaaa
I believe that the output should be one line, your program will probably produce factorial(14) lines of output.

Posted: Wed Apr 02, 2003 8:03 pm
by Hisoka
Thanks kmhasan, I know the problem now... :o

10098 Why output limit exceed

Posted: Sun May 18, 2003 11:55 am
by sleepchild
Pascal code
PROGRAM exp1_7;
var a:string;
p:char;
k,n,m,j,l,o:integer;
procedure swap(var a:string;k,i:integer);
var t:char;
begin
t:=a[k];a[k]:=a;a:=t;
end;
procedure perm(a:string;k,n:integer);
var i:integer;
begin
if k=n then writeln(a)
else for i:=k to n do
begin
swap(a,k,i);
perm(a,k+1,n);
end;
end;
BEGIN
readln(m);
for j:=1 to m do
begin
readln(a);
n:=length(a);
for o:=1 to n do
for l:=1 to n-1 do
if a[l]>a[l+1] then
begin
p:=a[l];
a[l]:=a[l+1];
a[l+1]:=p;
end;
perm(a,1,n);
writeln;
end;
end.


I think my program is right.
but why output limit exceed?

10098 Why output limit exceed

Posted: Sun May 18, 2003 11:56 am
by sleepchild
Pascal code
PROGRAM exp1_7;
var a:string;
p:char;
k,n,m,j,l,o:integer;
procedure swap(var a:string;k,i:integer);
var t:char;
begin
t:=a[k];a[k]:=a;a:=t;
end;
procedure perm(a:string;k,n:integer);
var i:integer;
begin
if k=n then writeln(a)
else for i:=k to n do
begin
swap(a,k,i);
perm(a,k+1,n);
end;
end;
BEGIN
readln(m);
for j:=1 to m do
begin
readln(a);
n:=length(a);
for o:=1 to n do
for l:=1 to n-1 do
if a[l]>a[l+1] then
begin
p:=a[l];
a[l]:=a[l+1];
a[l+1]:=p;
end;
perm(a,1,n);
writeln;
end;
end.


I think my program is right.
but why output limit exceed?

Posted: Sun May 18, 2003 1:33 pm
by little joey
You produce too much output :lol:

Think about the how many permutations of 'sleepchild' there are, and how many your program prints. (Too many, I can assure you!).

PS. Please use formatting tags when you publish code.

Posted: Mon May 19, 2003 4:00 am
by sleepchild
Thanks for your suggestion,but the problem need you to input char less than 10
can you tell me how to modify my program?