-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpermutation.java
42 lines (38 loc) · 1.02 KB
/
permutation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//UVa 482
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int cases = Integer.parseInt(line);
for(int i=0; i< cases; i++) {
br.readLine();
String[] index = br.readLine().split(" ");
String[] values = br.readLine().split(" ");
Pair[] list = new Pair[index.length];
for(int j=0; j < index.length ; j++) {
list[j] = new Pair(index[j], values[j]);
}
Arrays.sort(list);
for (Pair p : list) {
System.out.println(p.value);
}
if (i+1 < cases) {
System.out.println();
}
}
}
}
class Pair implements Comparable<Pair> {
public Integer x;
public String value;
public Pair(String x, String v) {
this.x = Integer.parseInt(x);
this.value = v;
}
public int compareTo(Pair p2) {
return this.x - p2.x;
}
}