UVA-482 - Permutation Arrays
Posted by Yung-Sheng Lu 15 Apr 2018
- UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt。
- 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
- 本題選為「20170328 大學程式能力檢定 CPE」題目。
題意概要
本題為編號 (Index) 和資料之間對應的排序,題目會在每一筆測資會給定一份編號,並按照 Index 給定對應的資料。以 Sample Input 為例,第一行為測資筆數,第二行為資料的編號,第三行為資料,所以編號為 的資料為 ,編號為 的資料為 ,以此類推。本題希望輸出為按照編號順序的所有資料。
- 分析:本題為簡單的資料結構應用,可以將編號存取在一個陣列,然後對應存取資料到另一個陣列。唯獨要注意的是,因為資料的型態可能為
int
、float
或是double
,所以可以#include <string>
以字串的型態來存取每一筆資料即可解決。另外,在最後輸出的格式,如過果是最後一筆測資,則不需要再多一個空行。
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. Each input set will contain two lines of numbers. The first line will be an index array containing the integers , … , where is the number of integers in the list. The numbers in the first line will have been permuted in some fashion. The second line will contain a list numbers in floating point format.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. The output for this program will be the list of floating point numbers from the input set, ordered according to the permutation array from the input file. The output numbers must be printed one per line in the same format in which they each appeared in the input file.
Sample Input
1
3 1 2
32.0 54.7 -2
Sample Output
54.7
-2
32.0