题解 | #简单错误记录#

简单错误记录

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> lst = new ArrayList<>();
        while (sc.hasNext()) {
            lst.add(sc.nextLine());
        }
        Map<String, Integer> map = new LinkedHashMap<>();
        for (String s : lst) {
            String[] a = s.split("\\\\");
            String str1 = a[a.length-1];
            String[] a2 = str1.split(" ");
            String s1 = a2[0];
            String s2 = s1.length() > 16 ? s1.substring(s1.length() - 16, s1.length()) : s1;
            String key = s2 + " " + a2[1];
            if (!map.containsKey(key)) {
                map.put(key, 0);
            }
            map.replace(key, map.get(key), map.get(key) + 1);
        }
        int num = map.size();
        int begin = num > 8 ? num - 8 : 0;
        int count = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (begin <= count) {
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
            count++;
        }
    }
}
全部评论

相关推荐

07-14 12:29
门头沟学院 Java
后端岗,实习三周感觉有点想跑路了,担心秋招被拉黑,有没有佬是字节HR知道情况的
从零开始的转码生活:你实习三周都想跑路,将来拿到offer真的愿意在这干十几二十年吗
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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