题解 | #简单错误记录#

简单错误记录

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

import java.util.Scanner;
import java.util.HashMap;
import java.util.LinkedHashMap;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        HashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
        while (in.hasNextLine()) {
            String[] elem = in.nextLine().split("\\s+");
            String[] adress = elem[0].split("\\\\");
            String lastName = adress[adress.length - 1];
            String fileName = lastName.substring(Math.max(0, lastName.length() - 16),
                                                 lastName.length());
            String record = fileName + " " + elem[1];
            if (map.containsKey(record)) {
                map.put(record, map.get(record) + 1);
            } else {
                map.put(record, 1);
            }

        }
        int count=0;
        for(String str:map.keySet()){
            count++;
            if(count>(map.keySet().size()-8))
            System.out.println(str+" "+map.get(str));
        }

}
}

全部评论

相关推荐

2025-12-31 14:19
门头沟学院 产品经理
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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