题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
int n = Integer.parseInt(sc.nextLine());
String[] arr = sc.nextLine().split(" ");
Map<String,Integer> map = new LinkedHashMap<>();
for (int i =0; i< arr.length;i++) {
map.put(arr[i], 0);
}
int k = Integer.parseInt(sc.nextLine());
String[] can = sc.nextLine().split(" ");
for (int i =0; i< can.length; i++) {
if (map.containsKey(can[i])) {
map.put(can[i], map.get(can[i]) + 1);
k--;
}
}
for (Map.Entry<String,Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
}
System.out.println("Invalid : " + k);
}
}
}