题解 | #记票统计#

记票统计

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNextLine()) {
            int m = Integer.parseInt(input.nextLine());
            String value = input.nextLine();
            String[] strings = value.split(" ");
            int n = Integer.parseInt(input.nextLine());
            String tickertvalue = input.nextLine();
            String[] tickertstrings = tickertvalue.split(" ");
            LinkedHashMap<String, Integer> hashMap = new LinkedHashMap<>();
            for (String string : strings) {
                hashMap.put(string, 0);
            }
            int use = 0;
            for (String tickertstring : tickertstrings) {
                if (hashMap.containsKey(tickertstring)) {
                    hashMap.put(tickertstring, hashMap.get(tickertstring) + 1);
                    use += 1;
                }
            }
            Set<Map.Entry<String, Integer>> entrySet = hashMap.entrySet();
            for (Map.Entry<String, Integer> stringIntegerEntry : entrySet) {
                System.out.println(stringIntegerEntry.getKey() + " : " +
                                   stringIntegerEntry.getValue());
            }

                System.out.println("Invalid : " + (tickertstrings.length - use));

            


        }

    }
}

全部评论

相关推荐

哇哇的菜鸡oc:他这不叫校招offer,而是实习offer
点赞 评论 收藏
分享
吃就完事了:别找单做硬件的找做电源的,电源工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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