题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n = in.nextInt(); Map<String, Integer> map = new LinkedHashMap<>(); for (int i = 0; i < n; i++) map.put(in.next(), 0); int num = in.nextInt(); int Invalid = 0; for (int i = 0; i < num; i++) { String s = in.next(); if (map.containsKey(s)) map.put(s, map.get(s) + 1); else Invalid++; } for (Map.Entry<String, Integer> e : map.entrySet()) System.out.println(e.getKey() + " : " + e.getValue()); System.out.println("Invalid : " + Invalid); } }