题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int hx = Integer.parseInt(br.readLine());
String[] mc = br.readLine().split(" ");
int xpNum = Integer.parseInt(br.readLine());
String[] xp = br.readLine().split(" ");
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < hx; i++) {
map.put(mc[i], map.getOrDefault(mc[i], 0));
}
map.put("Invalid", 0);
for (String str : xp) {
if (map.containsKey(str)) {
map.put(str, map.getOrDefault(str, 0) + 1);
} else {
map.put("Invalid", map.getOrDefault("Invalid", 0) + 1);
}
}
for (int i = 0; i < hx; i++) {
System.out.println(mc[i] + " : " + map.get(mc[i]));
}
System.out.println("Invalid" + " : " + map.get("Invalid"));
}
}
