UVa 482

From Algorithmist
Jump to navigation Jump to search

482 - Permutation Arrays[edit]

Summary[edit]

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

Explanation[edit]

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[edit]

  • 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[edit]

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

Input[edit]

2

3 1 2
32.0 54.7 -2

1 3 2 4
.004 +5.0e0 0.000007 3

Output[edit]

54.7
-2
32.0

.004
0.000007
+5.0e0
3

Solutions[edit]