题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=in.nextInt(); String[] people=new String[n]; HashMap<String,Integer> map=new HashMap<>(); for(int i=0;i<n;i++){ people[i]=in.next(); map.put(people[i],0); } int m=in.nextInt(); String[] select=new String[m]; for(int i=0;i<m;i++){ select[i]=in.next(); if(map.containsKey(select[i])){ map.put(select[i],map.get(select[i])+1); // System.out.println(select[i]+" == "+map.get(select[i])); } } int sum=0; for(int i=0;i<n;i++){ sum+=map.get(people[i]); System.out.println(people[i]+" : "+map.get(people[i])); } System.out.println("Invalid : "+(m-sum)); } }