UVa 482 - Permutation Arrays

482 - Permutation Arrays

 * http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=423

Summary
Output a series of floating point numbers in order defined by a given permutation.

Explanation
The plan is straightforward. Load the first line into an array A, allocate a secondary array with the same number of elements, and then put the i'th term of the second line into the (A[i]-1)'th entry of that array.

Gotchas

 * In order to maintain the format of the floating point numbers, you actually need to store them as strings.
 * The number of elements in the permutation and the length of the longest floating point number are unspecified and, by all indications, unreasonably large. If you statically type the floating point numbers as an array of character arrays, you will get a runtime error by either underestimating the size or by going beyond the (also unspecified) memory limits.

Implementations
Using STL's vector and string classes will eliminate the memory allocation concerns.

Input
2

3 1 2 32.0 54.7 -2

1 3 2 4 .004 +5.0e0 0.000007 3

Output
54.7 -2 32.0

.004 0.000007 +5.0e0 3

Solutions

 * Code All the Problems