题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.*; class b { String fileName; int line; b(){} b(String fileName, int line) { this.fileName = fileName; this.line = line; } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public int getLine() { return line; } public void setLine(int line) { this.line = line; } @Override public String toString() { return "(fileName:" + fileName + ", line:" + line + ")"; } @Override public int hashCode() { return Objects.hash(fileName,line); } @Override public boolean equals(Object o) { if (!(o instanceof b)) { return false; } b b = (b) o; return b.fileName.equals(this.fileName) && b.line == this.line; } } public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<b,Integer> map = new LinkedHashMap<>(100); while (sc.hasNext()) { String str = sc.nextLine(); String[] s = str.split(" "); // 行号 int line = Integer.parseInt(s[1]); String[] split = s[0].split("\\\\"); // 全名 String fileName = split[split.length - 1]; String name = fileName.length() > 16 ? fileName.substring(fileName.length() - 16) : fileName; b b = new b(name, line); map.put(b, map.getOrDefault(b,0) + 1); } // 输出 List<Map.Entry<b, Integer>> entries = new ArrayList<>(map.entrySet()); int len = entries.size(); int j = 0; if (len > 8) { j = len - 8; } for (; j < len; j++) { Map.Entry<b, Integer> e = entries.get(j); b b = e.getKey(); System.out.println(b.getFileName() + " " + b.getLine() + " " + e.getValue()); } } }