题解 | #记票统计#
记票统计
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 n = sc.nextInt(); String[] nname = new String[n]; for (int i = 0; i < n; i++) { nname[i] = sc.next(); } int m = sc.nextInt(); String[] str = new String[m]; for (int i = 0; i < m; i++) { str[i] = sc.next(); } HashMap<String, Integer> map = new HashMap<>(); for (String s : nname) { map.put(s, 0); } map.put("Invalid", 0); for (int i = 0; i < m; i++) { if (map.get(str[i]) != null) { map.put(str[i],map.get(str[i])+1); }else{ map.put("Invalid",map.get("Invalid")+1); } } for(String s : nname){ System.out.println(s+" : "+map.get(s)); } System.out.print("Invalid : "+map.get("Invalid")); } }