import java.util.*; public class LANQIAO { public static Map<String,Integer> map = new HashMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String name = sc.next(); // 判断set集合里是否有该书,有则++ 无则放入 if(map.containsKey(name)){ map.put(name,map.get(name) + 1); }else{ map.put(name,1); } } System.out.println(map.size()); // 得到map的键集合 遍历键和值 Set<String> set = map.keySet(); for (String s : set) { System.out.println(s + " " + map.get(s)); } } }
蓝桥杯真题-藏书问题
最新推荐文章于 2024-08-22 20:46:17 发布