输入格式:
输入分两行,分别在每行给出由若干个正整数构成的非降序序列,用−1表示序列的结尾(−1不属于这个序列)。数字用空格间隔。
输出格式:
在一行中输出合并后新的非降序链表,数字间用空格分开,结尾不能有多余空格;若新链表为空,输出NULL。
输入样例:
1 3 5 -1
2 4 6 8 10 -1
输出样例:
1 2 3 4 5 6 8 10

JAVAcode:

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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> in = new ArrayList<>();
Scanner sc = new Scanner(System.in);
int t;
for (int i = 0; i < 2; i++) {
while ((t = sc.nextInt()) != -1) {
in.add(t);
}
}
Collections.sort(in);
int leng=in.size();
if(leng<1) {
System.out.println("NULL");
return;
}
for (int i = 0; i < leng-1; i++) {
System.out.print(in.get(i)+" ");
}
System.out.println(in.get(leng-1));

}
}

PTA上检测能过,最后一个测试点内存超出规定大小了。