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

rakeb
New poster
Posts: 42
Joined: Fri Aug 30, 2002 2:51 pm
Location: France

10098 - Generating Fast

Post 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");

}
}

abiczo
New poster
Posts: 7
Joined: Sat Apr 06, 2002 2:00 am
Location: Hungary

Post 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
New poster
Posts: 42
Joined: Fri Aug 30, 2002 2:51 pm
Location: France

RAKEB

Post by rakeb »

thanx for reply

rakeb
New poster
Posts: 42
Joined: Fri Aug 30, 2002 2:51 pm
Location: France

PLZ help

Post by rakeb »

Now i m facing Runtime Error (SIGXFSZ) :o

rakeb
New poster
Posts: 42
Joined: Fri Aug 30, 2002 2:51 pm
Location: France

10098 Generating Fast, Sorted Permutation

Post by rakeb »

Can anybody give me outpus for

2
aABb
aabb

Thanx

Shahid
Learning poster
Posts: 68
Joined: Fri Oct 26, 2001 2:00 am
Location: Dhaka, Bangladesh
Contact:

not clear - the problem statement

Post 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?

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post 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(); )

Shahid
Learning poster
Posts: 68
Joined: Fri Oct 26, 2001 2:00 am
Location: Dhaka, Bangladesh
Contact:

what tweak it is?

Post 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 ...

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

10098

Post 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......

kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Location: Canada
Contact:

Post 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.

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

Thanks kmhasan, I know the problem now... :o

sleepchild
New poster
Posts: 3
Joined: Sun May 18, 2003 11:43 am

10098 Why output limit exceed

Post 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?

sleepchild
New poster
Posts: 3
Joined: Sun May 18, 2003 11:43 am

10098 Why output limit exceed

Post 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?

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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.

sleepchild
New poster
Posts: 3
Joined: Sun May 18, 2003 11:43 am

Post 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?

Post Reply

Return to “Volume 100 (10000-10099)”