题解 | #记票统计#

记票统计

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.hasNextLine()) {
                int n = Integer.parseInt(sc.nextLine());
                String[] arr = sc.nextLine().split(" ");
                Map<String,Integer> map = new LinkedHashMap<>();
                for (int i =0; i< arr.length;i++) {
                    map.put(arr[i], 0);
                }
                int k = Integer.parseInt(sc.nextLine());
                 String[] can = sc.nextLine().split(" ");
                for (int i =0; i< can.length; i++) {
                    if (map.containsKey(can[i])) {
                        map.put(can[i], map.get(can[i]) + 1);
                        k--;
                    }
                }
                for (Map.Entry<String,Integer> entry : map.entrySet()) {
                    System.out.println(entry.getKey() + " : " + entry.getValue());
                }
                System.out.println("Invalid : " + k);
            }
        }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
04-02 18:53
继京东给外卖员缴纳五险一金之后,京东又发公告:达达员工逐步升级至20薪!这是从去年以来京东宣布第8次加薪。别说了,我现在就是东孝子!!
无助的缄默:20薪拿不满的,前5%拿20薪,后面还有18,16,15,14薪,相当于把低绩效的人的工资补给高绩效的人
投递京东等公司7个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务