This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
int n = Integer.parseInt(scn.nextLine()); | |
while (n-- != 0) { | |
scn.nextLine(); | |
String arr[] = scn.nextLine().split(" "), arr2[] = scn.nextLine().split(" "), | |
ans[] = new String[arr.length]; | |
for (int i = 0; i < arr.length; i++) { | |
ans[Integer.parseInt(arr[i]) - 1] = arr2[i]; | |
} | |
for (int i = 0; i < ans.length; i++) { | |
System.out.println(ans[i]); | |
} | |
if (n != 0) | |
System.out.println(); | |
} | |
} | |
/*題目:Q482: Permutation Arrays | |
作者:1010 | |
時間:西元 2017 年 3 月 28日*/ | |
} |
這題Permutation顧名思義就是要交換排列,第一行n是接下來有幾筆測資,每筆測資第一行有一行空白要讀,輸出最後一個數字記得多加一個換行,但最後依筆測資不換行(這題光排版就被擺了一道,不過題目有說明)
每筆次資中有兩行,其中第一行以例子來說3 1 2是代表第二行測資每個數字的擺放位置,最簡單的實作方法就是再新增一個陣列依序擺放這些交換的數字囉,記得索引值index是從0開始
沒有留言:
張貼留言