题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/questionTerminal/67df1d7889cf4c529576383c2e647c48?answerType=1&f=discussion
重铸Java荣光,吾辈义不容辞
import java.util.*;
import java.lang.*;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
Map<String,Integer>map =new LinkedHashMap<>();
while(in.hasNextLine()){
String str = in.nextLine();
int index=str.lastIndexOf("\\");
str=str.substring(index+1,str.length());
if(map.containsKey(str)){
map.put(str,map.get(str)+1);
}else{
map.put(str,1);
}
}
map.entrySet().stream().sorted((o1,o2)->o2.getValue()-o1.getValue()).limit(8).forEach(e->{
int index=e.getKey().lastIndexOf(" ");
if(index>16){
System.out.println(e.getKey().subSequence(index-16,e.getKey().length())+" "+e.getValue());
}else{
System.out.println(e.getKey()+" "+e.getValue());
}
});
}
}