题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ int n = sc.nextInt(); LinkedHashMap<String,Integer> candidates = new LinkedHashMap<>(); for (int i = 0; i < n; i++) { String can = sc.next(); candidates.put(can,0); } int invalid = 0; int m = sc.nextInt(); for (int i = 0; i < m; i++) { String vote = sc.next(); if (candidates.containsKey(vote)){ candidates.put(vote,candidates.get(vote)+1); }else { invalid++; } } for (String name: candidates.keySet()){ System.out.println(name+" : "+candidates.get(name)); } System.out.println("Invalid : "+invalid); } } }