题解 | #记票统计#
记票统计
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 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case int n = Integer.parseInt(in.nextLine()); String str1 = in.nextLine(); String[] str1s = str1.split(" "); int m = Integer.parseInt(in.nextLine()); String str2 = in.nextLine(); String[] str2s = str2.split(" "); Map<String, Integer> map = new LinkedHashMap<>(); for(int i = 0;i<n;i++){ map.put(str1s[i],0); } int invalid = 0; for (int i = 0; i < m; i++) { String key = str2s[i]; if (map.containsKey(key)) { map.put(key, map.get(key) + 1); } else { invalid++; } } map.put("Invalid",invalid); for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } } } }