题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); Map<String, Integer> map = new LinkedHashMap<>(); for (int i = 0; i < n; i++) { map.put(in.next(), 0); } map.put("Invalid", 0); int m = in.nextInt(); in.nextLine(); String tmp = ""; for (int i = 0; i < m; i++) { tmp = in.next(); if(map.containsKey(tmp)){ map.put(tmp,map.get(tmp)+1); }else{ map.put("Invalid",map.get("Invalid")+1); } } map.forEach((a,b) -> { System.out.println(a +" : "+ b); }); } }