集合求差:

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = Integer.parseInt(sc.nextLine());
        Set<String> s = new HashSet<>();
        for(int i = 0; i < m; ++i) s.add(sc.nextLine());
        int n = Integer.parseInt(sc.nextLine());
        for(int i = 0; i < n; ++i) s.remove(sc.nextLine());
        List<String> r = new ArrayList<>(s);
        Collections.sort(r);    //按字典序输出
        for(String str : r) System.out.println(str);
    }
}