题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int peopleCount = Integer.parseInt(sc.nextLine()); LinkedHashMap<String, Integer> map = new LinkedHashMap(peopleCount); String[] peoples = sc.nextLine().split(" "); for (String people : peoples) { map.put(people, 0); } int voteCount = Integer.parseInt(sc.nextLine()); String[] votes = sc.nextLine().split(" "); int invalid = 0; for (String vote : votes) { if(map.containsKey(vote)){ map.put(vote, map.get(vote) + 1); } else { invalid++; } } for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } System.out.println("Invalid : " + invalid); } }