简单题
public static void main(String[] args) { Map<Integer, Integer> map = new TreeMap<Integer, Integer>(); Scanner sc = new Scanner(System.in); int size1 = sc.nextInt(); for (int i = 0; i < size1; i++) { int cur = sc.nextInt(); map.put(cur, map.containsKey(cur) ? map.get(cur) + 1 : 1); } int size2 = sc.nextInt(); for (int i = 0;i < size2; i++) { int cur = sc.nextInt(); map.put(cur, map.containsKey(cur) ? map.get(cur) - 1 : -1); } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() != 0) { System.out.print(entry.getKey() + " "); } } }