题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<String, Integer> map = new LinkedHashMap<>(); while (sc.hasNextLine()) { String s = sc.nextLine(); if ("".equals(s)) { break; } String[] split = s.split(" "); String[] paths = split[0].split("\\\\"); String path = paths[paths.length - 1]; String countStr = split[1]; path = path.length() > 16 ? path.substring(path.length() - 16) : path; path = path + " " + Integer.parseInt(countStr); if (map.containsKey(path)) { map.put(path, map.get(path) + 1); } else { map.put(path, 1); } } Set<String> strings = map.keySet(); int count = 0; for (String string : strings) { if (strings.size() - count <= 8) { System.out.println(string + " " + map.get(string)); } count++; } } }