题解 | #简单错误记录#

简单错误记录

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#
全部评论

相关推荐

炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
酷酷我灵儿帅:这去不去和线不线下面说实话没啥关系
点赞 评论 收藏
分享
这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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