题解 | #记票统计#

记票统计

http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Map<String, Integer> map = new LinkedHashMap<>();
            List<String> listCan = new ArrayList<>();
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                listCan.add(sc.next());
            }
            List<String> list = new ArrayList<>();
            int m = sc.nextInt();
            for (int i = 0; i < m; i++) {
                list.add(sc.next());
            }
            for (String s : listCan) {
                map.put(s, 0);
            }
            int invalidNum = 0;
            for (String s : list) {
                if(map.containsKey(s)){
                    map.put(s, map.get(s) + 1);
                }else{
                    invalidNum++;
                }
            }
            map.put("Invalid", invalidNum);
            for (Map.Entry<String, Integer> entry : map.entrySet()) {
                System.out.println(entry.getKey() + " : " + entry.getValue());
            }
        }
    }
}
全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务