题解 | #记票统计#
记票统计
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.hasNext()) { // 注意 while 处理多个 case
int n = in.nextInt();
in.nextLine(); //换行符
String[] peo = in.nextLine().split(" ");
//map需要使用LinkedHashMap来保证顺序
Map<String, Integer> map = new LinkedHashMap<>();
for(String s : peo){
map.put(s, 0);
}
int m = in.nextInt();
in.nextLine(); //换行符
String[] poll = in.nextLine().split(" ");
int invalid = 0;
for(String s : poll){
if(map.keySet().contains(s)){
map.put(s, map.get(s) + 1);
}else{
invalid++;
}
}
for(String k : map.keySet()){
System.out.println(k + " : " + map.get(k));
}
System.out.println("Invalid : " + invalid);
}
}
}
