题解 | #记票统计#
记票统计
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
in.nextLine();
String[] a = in.nextLine().split(" ");
LinkedHashMap<String,Integer> lhs = new LinkedHashMap<String,Integer>();
for(int i = 0 ; i < a.length ; i++){
lhs.put(a[i],0);
}
lhs.put("Invalid",0);
in.nextLine();
String[] b = in.nextLine().split(" ");
for(int i = 0 ; i < b.length ; i++){
if(lhs.get(b[i]) == null) {
lhs.put("Invalid",lhs.get("Invalid")+1);
} else {
lhs.put(b[i],lhs.get(b[i])+1);
}
}
lhs.forEach((w,v) -> {
System.out.println(w + " : " + v);
});
}
}
}