投票人只能投一票!!! | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("\n");
while (scanner.hasNextInt()) {
int ren = scanner.nextInt();
String[] names = scanner.next().split(" ");
int tou = scanner.nextInt();
String[] S = scanner.next().split(" ");
Map<String, Integer> hashMap = new LinkedHashMap<>();
for (int i = 0; i < names.length; i++) {
hashMap.put(names[i], 0);
}
hashMap.put("Invalid", 0);
for (int i = 0; i < S.length; i++) {
if (!hashMap.containsKey(S[i])) {
hashMap.put("Invalid", hashMap.get("Invalid")+1);
} else {
hashMap.put(S[i], hashMap.get(S[i])+1);
}
}
hashMap.entrySet().stream().forEach(o->{
System.out.println(o.getKey() + " : " + o.getValue());
});
}
}
}


