题解 | #记票统计#

记票统计

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);
            }
        }
}
全部评论

相关推荐

01-07 11:46
Java
如图:也是让我遇到逆天公司了,实习生是按天给工资,不忙直接强制休假了
baskly:公司为北京超图软件股份有限公司武汉分公司,明年公司应该会招新实习生,刷到的小伙伴快跑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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