题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<ArrayList<String>> records = new ArrayList<>();
HashMap<ArrayList<String>, Integer> recordsMistakes = new HashMap<>();
while (scan.hasNext()) {
String[] strs = scan.nextLine().split(" ");
String path = strs[0];
String index = strs[1].trim();
String[] tmps = path.split("\\\\");
String last = tmps[tmps.length - 1];
if (last.length() > 16) {
last = last.substring(last.length() - 16);
}
ArrayList<String> record = new ArrayList<>();
record.add(last);
record.add(index);
if (!records.contains(record)) {
records.add(record);
}
int mistake = recordsMistakes.getOrDefault(record, 0);
mistake++;
recordsMistakes.put(record, mistake);
}
if (records.size() <= 8) {
for (int i = 0; i < records.size(); i++) {
ArrayList<String> record = records.get(i);
System.out.println(record.get(0) + " " + record.get(1) + " " + recordsMistakes.get(record));
}
} else {
for (int i = records.size() - 8; i < records.size(); i++) {
ArrayList<String> record = records.get(i);
System.out.println(record.get(0) + " " + record.get(1) + " " + recordsMistakes.get(record));
}
}
}
}