题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
Map<String, Integer> map = new LinkedHashMap<>();
List<String> listCan = new ArrayList<>();
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
listCan.add(sc.next());
}
List<String> list = new ArrayList<>();
int m = sc.nextInt();
for (int i = 0; i < m; i++) {
list.add(sc.next());
}
for (String s : listCan) {
map.put(s, 0);
}
int invalidNum = 0;
for (String s : list) {
if(map.containsKey(s)){
map.put(s, map.get(s) + 1);
}else{
invalidNum++;
}
}
map.put("Invalid", invalidNum);
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
}
}
}
}