题解 | #简单错误记录#

简单错误记录

http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

LinkedHashMap的简单使用,只需要输出最后面的8条记录就好:

import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> map = new LinkedHashMap<>();
        while(sc.hasNextLine()){
            String str = sc.nextLine();
            String sub = str.substring(Math.max(str.lastIndexOf("\\") + 1, str.lastIndexOf(" ") - 16));
            Integer count = map.get(sub);
            if(count == null){
                map.put(sub, 1);
            }else{
                map.put(sub, count + 1);
            }
        }
        int index = 0;
        for(Map.Entry<String, Integer> e : map.entrySet()){
            if(map.size() - index <= 8){
                System.out.println(e.getKey() + " " + e.getValue());
            }
            ++ index;
        }
    }
}
全部评论

相关推荐

ResourceUtilization:四六级不愧是大学最有用的证之一
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务