482 - Permutation Arrays
Moderator: Board moderators
Search your problem first. Don't open a new thread if there is one already.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
Permutation array-482[RTE]!
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.
Please help me!
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
Last edited by abdullah<cse du> on Thu Apr 19, 2007 6:58 am, edited 3 times in total.
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
input and output for 482
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.
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.
In my compiler your code doesn't even pass the samples. Your input taking part is wrong. It can be like...
Hope it helps.
Code: Select all
scanf("%d\n",&test);
while(test--)
{
gets(input); // case starts
...
gets(input); // for taking the blank line between two consecutive cases
}
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
-
- New poster
- Posts: 9
- Joined: Sun Jan 08, 2006 9:57 pm
Hedge the input set you are trying with is not a correct one
this is your input set:
this is your input set:
the correct one should be: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
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
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
why wrong answer. need inputs and outputs.
thanx in advanced.
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.
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
HomePage
482 Permutation Arrays
ACed......
Last edited by aeiou on Fri Jun 20, 2008 1:19 pm, edited 1 time in total.
Re: 482 Permutation Arrays
There's no need to guess - use java.util.ArrayList instead of arrays, and it'll resize itself as needed.aeiou wrote:I changed the length of the array several times , but doesn't seem to work...
Don't forget that
so you have to read and skip it.there is also a blank line between two consecutive inputs
And remove the outer 'while(true) { ... }' loop in your code - there's only one set of inputs.
482 Permutation Arrays
ACed....
Last edited by aeiou on Fri Jun 20, 2008 1:18 pm, edited 1 time in total.
Re: 482 Permutation Arrays
Do you understand what this sentence is saying?
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:
It means that the input to your program looks something like this:http://acm.uva.es/p/v4/482.html wrote:... there is also a blank line between two consecutive inputs.
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
(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
Thanks mf....
Got AC...
Got AC...