题解 | #简单错误记录#

简单错误记录

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

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList<ArrayList<String>> records = new ArrayList<>();
        HashMap<ArrayList<String>, Integer> recordsMistakes = new HashMap<>();
        while (scan.hasNext()) {
            String[] strs = scan.nextLine().split(" ");
            String path = strs[0];
            String index = strs[1].trim();
            String[] tmps = path.split("\\\\");
            String last = tmps[tmps.length - 1];
            if (last.length() > 16) {
                last = last.substring(last.length() - 16);
            }
            ArrayList<String> record = new ArrayList<>();
            record.add(last);
            record.add(index);
            if (!records.contains(record)) {
                records.add(record);
            }
            int mistake = recordsMistakes.getOrDefault(record, 0);
            mistake++;
            recordsMistakes.put(record, mistake);
        }
        if (records.size() <= 8) {
            for (int i = 0; i < records.size(); i++) {
                ArrayList<String> record = records.get(i);
                System.out.println(record.get(0) + " " + record.get(1) + " " + recordsMistakes.get(record));
            }
        } else {
            for (int i = records.size() - 8; i < records.size(); i++) {
                ArrayList<String> record = records.get(i);
                System.out.println(record.get(0) + " " + record.get(1) + " " + recordsMistakes.get(record));
            }
        } 
    }
}
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 11:37

相关推荐

10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
一名愚蠢的人类:多少games小鬼留下了羡慕的泪水
投递荣耀等公司10个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务