- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathShellSort.java
More file actions
Latest commit
41 lines (37 loc) · 1.33 KB
/
Copy pathShellSort.java
File metadata and controls
41 lines (37 loc) · 1.33 KB
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
importstaticjava.util.stream.Collectors.toList;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.Collections;
importjava.util.List;
classShellSort {
privatestaticfinalBufferedReaderreader =
newBufferedReader(newInputStreamReader(System.in));
privatestaticList<String> getStrategy(List<String> input, List<String> target) {
inti = input.size() - 1;
intj = target.size() - 1;
while (i >= 0 && j >= 0) {
while (j >= 0 && !target.get(i).equals(input.get(j))) {
j--;
}
if (j < 0) {
break;
}
i--;
j--;
}
List<String> output = target.subList(0, i + 1);
Collections.reverse(output);
returnoutput;
}
publicstaticvoidmain(String[] args) throwsIOException {
intn = Integer.valueOf(reader.readLine().trim());
for (inti = 0; i < n; ++i) {
intcount = Integer.valueOf(reader.readLine().trim());
List<String> input = reader.lines().limit(count).collect(toList());
List<String> target = reader.lines().limit(count).collect(toList());
getStrategy(input, target).forEach(System.out::println);
System.out.println();
}
}
}