482 - Permutation Arrays

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

Moderator: Board moderators

Post Reply
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Search your problem first. Don't open a new thread if there is one already.
Ami ekhono shopno dekhi...
HomePage
abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

Permutation array-482[RTE]!

Post by abdullah<cse du> »

Hi,

I have submitted 482 for several of times. But every time i get run time error. Please help me to find my error. I am in trouble with this problem.

Code: Select all

Removed after AC
Please help me! :oops:
Last edited by abdullah<cse du> on Thu Apr 19, 2007 6:58 am, edited 3 times in total.
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

Post by Rocky »

to abdullah:
ur run time error cause for array size i think.....i submitted ur problem with the array size 100000 and it get WA....

GOOD LUCK
rocky
abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

input and output for 482

Post by abdullah<cse du> »

Hi,

I have changed array size and get wrong answer. Please give me some input and output to test my program.

Thanks Rocky for your help.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

In my compiler your code doesn't even pass the samples. Your input taking part is wrong. It can be like...

Code: Select all

    scanf("%d\n",&test);
    while(test--)
    {
        gets(input); // case starts
        ...
        gets(input); // for taking the blank line between two consecutive cases
    }
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

Post by abdullah<cse du> »

Jan bai,

Thanks Jan bai. I have got accepted. The problem in my input section.
spider_6765
New poster
Posts: 9
Joined: Sun Jan 08, 2006 9:57 pm

Post by spider_6765 »

Hedge the input set you are trying with is not a correct one

this is your input set:
5

3 1 2
32.0 54.7 -2
4 1 3 2
- 9.1 + 3. .9 .7
1 2 3
.1.2.3
4 3 2 1
-7.+.3.9 9.9
1 2
1.2.3
the correct one should be:

5

3 1 2
32.0 54.7 -2
<-a blank line here
4 1 3 2<-there is no such case, since the second string has 5 elements separated by space(' ') but the first string permutes only 4
- 9.1 + 3. .9 .7
<-a blank line here
1 2 3
.1.2.3
<-a blank line here
4 3 2 1
-7.+.3.9 9.9
<-a blank line here
1 2
1.2.3
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

why wrong answer. need inputs and outputs.

Code: Select all



/*
       Author        : Newton
	   Problem name  : Permutation array [482]
	   Algorithm     : Simple string, strtok
*/


#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 

char strings[20000][50],str[100000]; 
int num[20000]; 

int main() 
{ 
	int test,i,j;
	char *p; 
	//freopen("input.txt","rt",stdin); 
	
	scanf("%d\n",&test); 
	while(test--) 
	{ 
		gets(str); 
		
		i = 0; 
		p = strtok(str," ");            
		
		while(p) 
		{
			sscanf(p,"%d",&num[i]);
			i++; 
			p = strtok(NULL," "); 
		} 
		
		gets(str); 
		i = 0; 
		p = strtok(str," "); 
		while(p) 
		{ 
			sscanf(p,"%s",strings[num[i]]); 
			p = strtok(NULL," ");          
			i++; 
		} 
		for(j = 1; j<=i ;j++) 
			printf("%s\n",strings[j]); 

		if(test)
			puts("");
	} 
	//fclose(stdin);
	return 0; 
} 


thanx in advanced.
Last edited by newton on Mon Jul 23, 2007 2:53 pm, edited 3 times in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

If you are submitting in C++, then you can have problems. 'string' is a predefined class. So, change the name of your 'string' array. Hope it helps.
Ami ekhono shopno dekhi...
HomePage
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 »

no need to tokenized both string.

---just create for index
---then use scanf("%s") for every value.
---print the 2D string.
hope it helps.
''I want to be most laziest person in the world''
aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

482 Permutation Arrays

Post by aeiou »

ACed......
Last edited by aeiou on Fri Jun 20, 2008 1:19 pm, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 482 Permutation Arrays

Post by mf »

aeiou wrote:I changed the length of the array several times , but doesn't seem to work...
There's no need to guess - use java.util.ArrayList instead of arrays, and it'll resize itself as needed.

Don't forget that
there is also a blank line between two consecutive inputs
so you have to read and skip it.

And remove the outer 'while(true) { ... }' loop in your code - there's only one set of inputs.
aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

482 Permutation Arrays

Post by aeiou »

ACed....
Last edited by aeiou on Fri Jun 20, 2008 1:18 pm, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 482 Permutation Arrays

Post by mf »

Do you understand what this sentence is saying?
http://acm.uva.es/p/v4/482.html wrote:... there is also a blank line between two consecutive inputs.
It means that the input to your program looks something like this:

Code: Select all

3

3 1 2
32.0 54.7 -2

3 1 2
32.0 54.7 -2

3 1 2
32.0 54.7 -2
Note the blank lines!

(Ignore all of the above posts where there are no blank lines - they're wrong.
Token-by-token input ala C's scanf() doesn't care about them, but if you read the input line-by-line it matters)


And, just for completeness, the output for the above input is, of course:

Code: Select all

54.7
-2
32.0

54.7
-2
32.0

54.7
-2
32.0
aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

482 Permutation Arrays

Post by aeiou »

Thanks mf....
Got AC...
Post Reply

Return to “Volume 4 (400-499)”