-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path281.java
More file actions
44 lines (40 loc) · 1000 Bytes
/
281.java
File metadata and controls
44 lines (40 loc) · 1000 Bytes
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
43
44
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Scanner;
public class Solution {
void sgu281 () {
Hashtable <String, Integer> dic = new Hashtable <String, Integer> ();
String s;
ArrayList<String> t = new ArrayList<String> ();
int n, i, k;
Scanner in = new Scanner (new BufferedInputStream (System.in));
n = in.nextInt ();
for (i = 0; i < n; ++i) {
s = in.next();
dic.put (s, i);
}
int last = 0;
for (k = 0; k < n; ++k) {
s = in.next();
t.add (s);
last = Math.max (last, dic.get(s));
if (last == k) {
Collections.sort(t, new Comparator<String> () {
public int compare (String a, String b) {
return a.compareTo(b);
}
});
for (String str : t)
System.out.println(str);
t.clear();
}
}
}
public static void main(String[] args) {
Solution sguSolver = new Solution ();
sguSolver.sgu281 ();
}
}