题解 | #简单错误记录#

简单错误记录

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++;
        }
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务