题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.Scanner;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
HashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
while (in.hasNextLine()) {
String[] elem = in.nextLine().split("\\s+");
String[] adress = elem[0].split("\\\\");
String lastName = adress[adress.length - 1];
String fileName = lastName.substring(Math.max(0, lastName.length() - 16),
lastName.length());
String record = fileName + " " + elem[1];
if (map.containsKey(record)) {
map.put(record, map.get(record) + 1);
} else {
map.put(record, 1);
}
}
int count=0;
for(String str:map.keySet()){
count++;
if(count>(map.keySet().size()-8))
System.out.println(str+" "+map.get(str));
}
}
}

查看22道真题和解析