题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); Map<String,Integer> dataMap = new LinkedHashMap<>(); Map<String, String> rootMap = new HashMap<>(); while (in.hasNext()) { String input = in.nextLine(); if(input.equals("")){ break; } String fileAddr = input.split(" ")[0]; String errorLine = input.split(" ")[1]; String errorClazz = fileAddr.substring(fileAddr.lastIndexOf("\\")+1); if(errorClazz.length() > 16){ errorClazz = errorClazz.substring(errorClazz.length() - 16); } String key = errorClazz+":"+errorLine; if(dataMap.get(key) == null){ dataMap.put(key,1); } else { dataMap.put(key,dataMap.get(key)+1); } } dataMap.entrySet().stream().skip(dataMap.size() - 8>0 ? dataMap.size() - 8 : 0).forEach(a -> System.out.println(a.getKey().split(":")[0]+" "+ a.getKey().split(":")[1]+" "+a.getValue())); } }