import java.util.Scanner;
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
while (in.hasNextLine()) { // 注意 while 处理多个 case
String line = in.nextLine();
String[] f = line.split(" ")[0].split("\\\\");
String file = f[f.length - 1];
if (file.length() > 16) file = file.substring(file.length() - 16);
String rn = line.split(" ")[1];
String key = file + " " + rn;
map.put(key, map.getOrDefault(key, 0)+1);
}
int count=0;
for (String key : map.keySet()) {
if(map.size()-count<=8)
System.out.println(key.split(" ")[0] + " "
+ key.split(" ")[1] + " " + map.get(key));
count++;
}
}
}
- LinkedHashMap保证有序
- map.getOrDefault(key, 0)+1 别忘记+1;
- 注意,取最后8条记录的取法