题解 | #记票统计#

记票统计

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

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int num1 = in.nextInt();
        in.nextLine();
        String s1 = in.nextLine();
        String[] c1 = s1.split(" ");
        LinkedHashMap<String, Integer> lhm = new LinkedHashMap<String, Integer>();
        for(int i = 0; i<num1; i++){
            lhm.put(c1[i],0);
        }//候选人
        int num2 = in.nextInt();
        in.nextLine();
        String s2 = in.nextLine();
        String[] c2 = s2.split(" ");
        int ill =0;
        for(int i = 0; i<num2; i++){
            String ch = c2[i];
            if( ! lhm.containsKey(ch) ){ ill++; }
            else{ lhm.put( ch, lhm.get(ch)+1); }//如果包含KEY,直接放入put(key, value+1)
        }//for_i
        for(String key: lhm.keySet() ){
            System.out.println(key+" : "+lhm.get(key));
        }
        System.out.println("Invalid : "+ill);
    }//main
}//Main
全部评论

相关推荐

合不合适,我自己说了才算
码农索隆:hr:“真执着啊,来我公司当法人吧”
点赞 评论 收藏
分享
牛客73617529...:无端端被你骂一句
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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