题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.LinkedHashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); LinkedHashMap<String, Integer> map = new LinkedHashMap<>(); while (scanner.hasNextLine()) { String[] values = scanner.nextLine().split("\\s+"); String name = values[0].substring(values[0].indexOf("\\") + 1); name = name.substring(Math.max(name.length() - 16, 0)) + " " + values[1]; map.put(name, map.getOrDefault(name, 0) + 1); } // 输出最后八个记录 int count = 0; for (String string : map.keySet()) { count++; if (count > (map.keySet().size() - 8)) System.out.println(string + " " + map.get(string)); } } }