代码如下:
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Scanner;
public class ErrorRecord {
public static void main(String[] args) {
LinkedHashMap<String,Integer> map = new LinkedHashMap<String,Integer>();
String[] record = new String[8];
Scanner scan = new Scanner(System.in);
int count = 0;
String str = null;
while(scan.hasNext())
{
str = scan.next();
int index = str.lastIndexOf('\\');
str = str.substring(index + 1);
if(str.length() > 16)
{
str = str.substring(str.length() - 16, str.length());// substring(a,b)不包括下标为b的字符
}
String left = str+" " + scan.nextInt();
if(map.containsKey(left)){
int value = map.get(left);
map.put(left, value+1);
}else{
record[count%8] = left;
map.put(left, 1);
count++;
}
}
for(int i=count%8;i<8;i++){
if(record[i]!=null){
int time = map.get(record[i]);
System.out.println(record[i]+" "+time);
}
}
for(int i=0;i<count%8;i++){
if(record[i]!=null){
int time = map.get(record[i]);
System.out.println(record[i]+" "+time);
}
}
scan.close();
}
}