Page 7 of 11

Posted: Mon Apr 16, 2007 10:27 pm
by Jan
Search your problem first. Don't open a new thread if there is one already.

Permutation array-482[RTE]!

Posted: Wed Apr 18, 2007 8:27 am
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:

Posted: Wed Apr 18, 2007 9:30 am
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

input and output for 482

Posted: Wed Apr 18, 2007 10:55 am
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.

Posted: Wed Apr 18, 2007 5:27 pm
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.

Posted: Thu Apr 19, 2007 7:02 am
by abdullah<cse du>
Jan bai,

Thanks Jan bai. I have got accepted. The problem in my input section.

Posted: Thu Jul 19, 2007 3:06 pm
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

Posted: Sun Jul 22, 2007 3:59 pm
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.

Posted: Sun Jul 22, 2007 8:58 pm
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.

Posted: Wed Feb 27, 2008 10:05 pm
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.

482 Permutation Arrays

Posted: Mon Jun 16, 2008 10:43 am
by aeiou
ACed......

Re: 482 Permutation Arrays

Posted: Mon Jun 16, 2008 11:09 am
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.

482 Permutation Arrays

Posted: Mon Jun 16, 2008 3:01 pm
by aeiou
ACed....

Re: 482 Permutation Arrays

Posted: Mon Jun 16, 2008 3:19 pm
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

482 Permutation Arrays

Posted: Fri Jun 20, 2008 1:17 pm
by aeiou
Thanks mf....
Got AC...