Page **1** of **11**

Posted: **Fri Jan 04, 2002 6:34 am**

by **yatsen**

I was confused by the sample input & sample output. Is the sample output right? I think it should be -2 32.0 54.7

And I got Runtime Error (SIGSEGV)

What is wrong with my program.

Sample Input

3 1 2

32.0 54.7 -2

Sample Output

54.7

-2

32.0

Posted: **Sun Jan 06, 2002 9:13 pm**

by **Adrian Kuegel**

Perhaps your array is not big enough?

I have used an array with 1000000 elements.

The integers on the first line of input are the indizes from the array, which is wanted. In the same order appear the elements of this array. You have to reorder the elements so that their indizes are ordered.

### wrong sample input and output

Posted: **Mon Apr 22, 2002 12:06 pm**

by **Shahid**

hi,

i also guess the sample input and output given in the problem description is wrong and yasten is right. Can anyone plz confirm me about the matter?

thwe right output for the sample input:

3 1 2

32.0 54.7 -2

should be:

-2

32.0

54.7

Posted: **Mon Apr 22, 2002 7:26 pm**

by **Adrian Kuegel**

No, it is ok. The description says:

"Then, we have the relationship between x and x' that x'pi = xi."

That means that at position i there is the index value for x after permutation, for example if you have

2 1

-2 2

then -2 has to be at position 2 in the reordered array and 2 at position 1.

For the sample input there is p1=3, therefore in the permutated array there should be at position 3 the same value as at position 1, and so on.

Posted: **Fri Apr 26, 2002 4:11 am**

by **C8H10N4O2**

The right output for the sample input:

3 1 2

32.0 54.7 -2

should be:

54.7

-2

32.0

Posted: **Thu Dec 12, 2002 3:20 pm**

by **anupam**

**can any1 tell me what the problem is in my program.**

thanks in adv.

Code: Select all

```
[cpp]
#include<stdio.h>
#include<stdlib.h>
#define N 10000
main()
{
int n,z,i,l,k,m,b[N];
char ch,c[50],d[N][20];
scanf("%d",&n);
scanf("%c",&ch);
for(z=0;z<n;z++)
{
k=0;
while(1)
{
m=0;
while(1)
{
scanf("%c",&ch);
if(ch=='\n' && k) break;
if(ch==' ') break;
if(ch!='\n' && ch!=' ')c[m++]=ch;
}
c[m]=0;
b[k++]=atoi(c);
if(ch=='\n') break;
}
for(i=0;i<k;i++)
scanf("%s",d[i]);
l=1;
for(m=0;m<k;m++)
{
for(i=0;i<k;i++)
if(b[i]==l)
{
printf("%s\n",d[i]);
l++;
break;
}
}
if(z!=(n-1)) printf("\n");
}
return 0;
}[/cpp]
```

[/b]

### 2 anupam

Posted: **Fri Dec 13, 2002 12:07 am**

by **the LA-Z-BOy**

well, well, this problem is very good one (!) for handling the input. anyway, now let's talk 'bout your code here.

while taking the index array in the first part, you're incrementing k (the number of array element) all the time, even if a whitespace occurs!

it should be rather,

that is you should only increment k when you got a number. Secondly, your check in the inner while loop

should be simply

i think this causes a time limit exceed.

Again the check in the outer while loop should be,

rather than

it should help

.

___________

the LA-Z-BOy

Posted: **Sat Dec 14, 2002 7:05 am**

by **anupam**

thanks u very much.

after wasting a lot of time and taking your advices in mind i got it ac.

thanks again.

Posted: **Mon Dec 16, 2002 7:38 pm**

by **junjieliang**

Before editing: "Can someone give me any tricky tests? My program should handle whitespace without problems at all...but it gets WA

"

Found my error...AC

Constants for my program

=> Max numbers: 100000

=> Max length per number: 100

Hope this will help others

Posted: **Tue Dec 17, 2002 5:58 am**

by **the LA-Z-BOy**

junjieliang wrote:
Found my error...AC

Constants for my program

=> Max numbers: 100000

=> Max length per number: 100

Hope this will help others

my solution that got accepted assumes

=> Max numbers: 32000

=> Max len per number: 55 (54)

but later when i worked with anupam's code i got the upper bound more accurate

=> Max numbers: 2000

=> Max len per number: 15 (14)

Max bound may be lower than this even, I haven't tried .

___________

the LA-Z-BOy

Posted: **Wed Dec 18, 2002 10:37 am**

by **anupam**

**i got rte because i didn't consider the break case properly.**

please check my preveous program that is corrected by a great helper.

i think you will understand.

thanks.

### 482 Permutation Arrays - WA, RE <SIGSEGV>

Posted: **Wed Feb 12, 2003 10:58 am**

by **Hunter**

Guys, please check my 482 code downhere:

[cpp]#include <stdio.h>

#include <math.h>

#include <string.h>

char str[10000],n[1000][10000],chr;

int len,count,ten,temp,i,j,k,sum[10000],m,cas;

void main ()

{

scanf ("%d",&m); cas=0;

scanf ("%c",&chr); //to handle an <Enter> after inputting the m

while (cas<m)

{

cas++; count=1; k=0; temp=0;

while (scanf ("%c",&chr)==1)

{

if (chr==' ' || chr=='\n')

{

temp++; len=strlen(str); sum[temp]=0;

for (i=len-1;i>=0;i--)

{

switch (str*)*

{

case '0': {sum[temp]+=0; break;} case '5': {sum[temp]+=5*pow(10,ten); break;}

case '1': {sum[temp]+=1*pow(10,ten); break;} case '6': {sum[temp]+=6*pow(10,ten); break;}

case '2': {sum[temp]+=2*pow(10,ten); break;} case '7': {sum[temp]+=7*pow(10,ten); break;}

case '3': {sum[temp]+=3*pow(10,ten); break;} case '8': {sum[temp]+=8*pow(10,ten); break;}

case '4': {sum[temp]+=4*pow(10,ten); break;} case '9': {sum[temp]+=9*pow(10,ten); break;}

}

ten++;

}

for (i=0;i<len;i++)

{

str*='\0';*

}

k=0;; count++; ten=0;

}

else {str[k]=chr; k++;}

if (chr=='\n') break;

}

for (i=1;i<=temp;i++)

{

scanf ("%s",n[sum*]);*

}

for (i=1;i<=temp;i++)

{

printf ("%s\n",n*);*

}

if (cas<m) printf ("\n");

scanf ("%c",&chr); //to handle the printf ("\n");

}

}[/cpp]

I played with the first and the last "scanf ("%c",&chr);" and I got either RE <SIGSEGV> or WA...

I think I've gone wrong handlin' the input... An <Enter> after the previous input is always

taken by the "scanf ("%c",&chr);" as a '\n' character, so it just passed with the wrong input ('\n')...

Anybody, please tell me how to overcome this. Or maybe found me another mistake(s)???

Thank's!

### Please reply...

Posted: **Mon Feb 17, 2003 10:45 am**

by **Hunter**

Heey... isn't there any solved this problem yet?

Please gimme answers... Really need it!!!

Thank you.

### Answer meeee....

Posted: **Sun Mar 16, 2003 7:12 am**

by **Hunter**

**It's been a long time...**

Why there's still no answer?

I grew the array to a million but nothing happened but another 0.023 SIGSEGV RE!!

Why??!

Posted: **Mon Mar 17, 2003 9:19 pm**

by **saiqbal**

u'd better try to use struct and store every number as string (important! bcoz

u need to print exactly the same as input) and corresponding indices and sort

the array according to the indices. u can use qsort for sorting.

following code might help:

[c]

typedef struct

{

int index;

char num[20];

} array;

array a[100000];

[/c]

good luck

-sohel