题解 | #记票统计#

记票统计

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int peopleCount = Integer.parseInt(sc.nextLine());
        LinkedHashMap<String, Integer> map = new LinkedHashMap(peopleCount);
        String[] peoples = sc.nextLine().split(" ");
        for (String people : peoples) {
            map.put(people, 0);
        }
        int voteCount = Integer.parseInt(sc.nextLine());
        String[] votes = sc.nextLine().split(" ");
        int invalid = 0;
        for (String vote : votes) {
            if(map.containsKey(vote)){
                map.put(vote, map.get(vote) + 1);
            } else {
                invalid++;
            }
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }
        System.out.println("Invalid : " + invalid);
    }
}

全部评论

相关推荐

强大的马里奥:我初中同学,没上高中,搞直播,现在提奔驰S450了
点赞 评论 收藏
分享
炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务