题解 | #记票统计#

记票统计

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 n = sc.nextInt();
        String[] nname = new String[n];
        for (int i = 0; i < n; i++) {
            nname[i] = sc.next();
        }
        int m = sc.nextInt();
        String[] str = new String[m];
        for (int i = 0; i < m; i++) {
            str[i] = sc.next();
        }
        HashMap<String, Integer> map = new HashMap<>();
        for (String s : nname) {
            map.put(s, 0);
        }
        map.put("Invalid", 0);
        for (int i = 0; i < m; i++) {
            if (map.get(str[i]) != null) {
                map.put(str[i],map.get(str[i])+1);
            }else{
                map.put("Invalid",map.get("Invalid")+1);
            }
        }
        for(String s : nname){
            System.out.println(s+" : "+map.get(s));
        }
        System.out.print("Invalid : "+map.get("Invalid"));
    }
}

全部评论

相关推荐

码客明:其实东西都是那一套,但是不同的方向会自己造轮子,然后方便汇报。一个同样的工具不同的方向做好几个工具,然后大同小异,汇报的时候说根据我们的团队和业务情况开发一个适合我们平台的xx工具。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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