集合求差

超链接

http://www.nowcoder.com/questionTerminal/f459f298ca814040bf601004734129a9

集合求差:

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);
    }
}
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务