题解 | #简单错误记录#

简单错误记录

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

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] arge) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str;
        LinkedHashMap<String,Integer> map = new LinkedHashMap<>();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String nextLine = scanner.nextLine();
            String[] split = nextLine.split(" ");
            String preStr = split[0];
            String[] split1 = preStr.split("\\\\");
            String lastStr = split1[split1.length - 1];
            lastStr = lastStr.length()>16?lastStr.substring(lastStr.length()-16):lastStr;
            lastStr = lastStr+" "+split[1];
            if (!map.containsKey(lastStr)){
                map.put(lastStr,1);
            }else {
                map.put(lastStr,map.get(lastStr)+1);
            }
        }
        int count = 0;
        int index = 0;
        for (String s : map.keySet()) {
            if (count<8&&index++>=map.size()-8){
                count++;
                System.out.println(s+" "+map.get(s));
            }
        }

        
    }
}
使用linkedhashmap记录插入顺序 使用count 和index将倒数8个正序输出 前面都是一个字符串操作 
#华为od#
全部评论

相关推荐

2024-12-23 11:36
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务