题解 | #记票统计#

记票统计

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

import java.util.*;

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

}
全部评论

相关推荐

独玖:同二本,建议咱俩一起重开
点赞 评论 收藏
分享
02-17 20:43
西北大学 Java
在做测评的猫头鹰很紧张:他问你,你问deep seek
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务