Posted: Mon Apr 16, 2007 10:27 pm
Search your problem first. Don't open a new thread if there is one already.
Code: Select all
Removed after AC
Code: Select all
scanf("%d\n",&test);
while(test--)
{
gets(input); // case starts
...
gets(input); // for taking the blank line between two consecutive cases
}
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
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;
}
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...
so you have to read and skip it.there is also a blank line between two consecutive inputs
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
Code: Select all
54.7
-2
32.0
54.7
-2
32.0
54.7
-2
32.0