牛客网问题

牛客网94题候选人投票问题 题干描述:输入候选人的人数n,第二行输入n个候选人的名字(均为大写字母的字符串),第三行输入投票人的人数,第四行输入投票。 输入: 4 A B C D 8 A D E CF A GG A B 输出: A : 3 B : 1 C : 0 D : 1 Invalid : 3

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
          
            int n = Integer.parseInt(in.nextLine());
            String a = in.nextLine();
            int p = Integer.parseInt(in.nextLine());
            String b = in.nextLine();
            int count = 0;
            Map<String,Integer> map = new LinkedHashMap<>();
            for(String str:a.split(" ")){
                map.put(str,0);
            }
            for(String str:b.split(" ")){
                if(map.containsKey(str)){
                    map.put(str,map.get(str)+1);
                    count++;
                }
            }
            for(String key:map.keySet()){
                System.out.println(key+" : "+map.get(key));
            }
            System.out.println("Invalid : "+(p-count));
        }
    }
}

全部评论

相关推荐

优秀的大熊猫在okr...:多益:此贼,必有同谋,按律,该当连坐!
你不能接受的企业文化有哪...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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