import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); List<Integer> A = new ArrayList<>(); for (int i = 0; i < n; i++) { A.add(scanner.nextInt()); } int m = scanner.nextInt(); List<Integer> B = new ArrayList<>(); for (int i = 0; i < m; i++) { B.add(scanner.nextInt()); } List<Integer> U = new ArrayList<>(); U.addAll(B); B.retainAll(A); A.removeAll(B); U.addAll(A); Collections.sort(U); Collections.sort(A); Collections.sort(B); for (int i = 0; i < B.size(); i++) { System.out.print(B.get(i)); System.out.print(i == B.size() - 1 ? "\r\n" : " "); } for (int i = 0; i < U.size(); i++) { System.out.print(U.get(i)); System.out.print(i == U.size() - 1 ? "\r\n" : " "); } for (int i = 0; i < A.size(); i++) { System.out.print(A.get(i)); System.out.print(i == A.size() - 1 ? "\r\n" : " "); } } } }
原文地址:http://blog.csdn.net/u011506951/article/details/27197635