20
0 ab
6 cd
0 ef
6 gh
4 ij
0 ab
6 cd
0 ef
6 gh
0 ij
4 that
3 be
0 to
1 be
5 question
1 or
2 not
4 is
2 to
4 the

範例輸出

- - - - - to be or not to be - that is the question - - - -

0 ab(-)
0 ef(-)
0 ab(-)
0 ef(-)
0 ij(-)
0 to
1 be
1 or
2 not
2 to
3 be
4 ij(-)
4 that
4 is
4 the
5 question
6 cd(-)
6 gh(-)
6 cd(-)
6 gh(-)

參考答案

```import java.util.*;

public class Solution {

public static void main(final String[] args) {
final Scanner in = new Scanner(System.in);
final int n = Integer.parseInt(in.nextLine());

final int[] A = new int[n];
final String[] S = new String[n];
final int[] count = new int[100];
final int n_half = n / 2;
for (int i = 0; i < n; ++i) {
final String[] tokens = in.nextLine().split(" ");
A[i] = Integer.parseInt(tokens[0]);
if (i < n_half) {
S[i] = "-";
} else {
S[i] = tokens[1];
}
++count[A[i]];
}
for (int i = 1; i < 100; ++i) {
count[i] = count[i] + count[i - 1];
}
final String[] S2 = new String[n];
for (int i = n - 1; i >= 0; --i) {
final int a = A[i];
S2[--count[a]] = S[i];
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; ++i) {
sb.append(S2[i]).append(" ");
}
System.out.println(sb.toString().trim());
}
}```