题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] s = br.readLine().split(" "); int v = Integer.parseInt(br.readLine()); String[] vote = br.readLine().split(" "); int temp = 0; //有效长度 for(int i = 0;i < n;i++){ int sum = 0; for(int j = 0;j < v;j++){ if(s[i].equals(vote[j])){ sum ++; } } System.out.println(s[i]+" : "+sum); temp += sum; } System.out.println("Invalid : " + (v - temp)); } }