题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
//候选人数
int n = sc.nextInt();
//候选人
String[] man = new String[n];
for (int i = 0; i < n; i++) {
man[i] = sc.next();
}
//投票人数
int m = sc.nextInt();
//投的票
String[] votes = new String[m];
for (int i = 0; i < m; i++) {
votes[i] = sc.next();
}
int invalid = m;
for (String s : man) {
int count = 0;
for (String vote : votes) {
if (s.equals(vote)) {
count++;
}
}
System.out.println(s + " : " + count);
invalid -= count;
}
System.out.println("Invalid : " + invalid);
}
}
}


