10098 - Generating Fast
Moderator: Board moderators
10098 - Generating Fast
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");
}
}
#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");
}
}
10098 Generating Fast, Sorted Permutation
Can anybody give me outpus for
2
aABb
aabb
Thanx
2
aABb
aabb
Thanx
-
- Learning poster
- Posts: 68
- Joined: Fri Oct 26, 2001 2:00 am
- Location: Dhaka, Bangladesh
- Contact:
not clear - the problem statement
in the problem statement one sentense is :
is it means that the strings should not be treated as case sensitive strings or it means the opposite?
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?
-
- Learning poster
- Posts: 68
- Joined: Fri Oct 26, 2001 2:00 am
- Location: Dhaka, Bangladesh
- Contact:
what tweak it is?
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
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
THANX......
[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

THANX......
Try the following input:
I believe that the output should be one line, your program will probably produce factorial(14) lines of output.
Code: Select all
1
aaaaaaaaaaaaaa
K M Hasan
http://www.cs.umanitoba.ca/~kmhasan/
http://www.cs.umanitoba.ca/~kmhasan/
-
- New poster
- Posts: 3
- Joined: Sun May 18, 2003 11:43 am
10098 Why output limit exceed
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?
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?
-
- New poster
- Posts: 3
- Joined: Sun May 18, 2003 11:43 am
10098 Why output limit exceed
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?
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?
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
-
- New poster
- Posts: 3
- Joined: Sun May 18, 2003 11:43 am