rambless

简单错误记录

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

import java.util.*;
import java.io.*;


// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        // 注意 hasNext 和 hasNextLine 的区别
        Map<String,Integer> map = new LinkedHashMap<>();
        List<String> list = new ArrayList<>();
        String temp;
        while ((temp = in.readLine()) != null && temp.length() > 0) {
            //循环记录时
            if(!list.contains(temp)) {
                String[] array = temp.split(" ");
                String num = array[1];
                String name = array[0];
                name = name.substring(name.lastIndexOf("\\") + 1);
                name = name.substring(Math.max(name.length() - 16, 0)) + " " + num;
                Integer count = map.get(name);
                if(count==null) {
                    map.put(name, 1);
                } else {
                    map.put(name, ++count);
                }
            }
        }
        //记录最多8条错误记录
        int count = 0;
        for(String s:map.keySet()) {
            if(map.size()-count<=8) {
                System.out.println(s + " " + map.get(s));
            }
            count++;
        }
    }
}

全部评论

相关推荐

qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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