LinkedHashMap | #记票统计#
记票统计
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 num = in.nextInt(); LinkedHashMap<String, Integer> map = new LinkedHashMap<>(); for(int i=0;i<num;i++)map.put(in.next(),0); int invalid = 0; int voteNum = in.nextInt(); for(int i=0;i<voteNum;i++){ String role = in.next(); if(map.containsKey(role))map.put(role, map.get(role)+1); else invalid++; } for(String c : map.keySet()) System.out.printf("%s : %d\n",c,map.get(c)); System.out.printf("Invalid : %d",invalid); } }