题解 | #简单错误记录#

简单错误记录

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

暴力模拟,欢迎指出问题

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        List<Node> list = new ArrayList<>();    
        int cnt = 0;
        while (sc.hasNext()) { 
            String[] tar = sc.next().split("\\\\");
            String filename = tar[tar.length-1];    
            int line = sc.nextInt();
            if(filename.length() > 16){
                filename = filename.substring(filename.length()-16);               
            }
            boolean flag = false;
            for(int j= 0; j < list.size(); j++){
                Node p = list.get(j);
                if(p.fileName.equals(filename) && p.line == line){
                    p.cnt++;
                    flag = true;
                    break;                    
                }                             
            }
            if(!flag)
            list.add(new Node(filename,line,1));           

            if(list.size() > 8 && !flag){
                cnt++;
            }
        }
        
        for(int j= 0,i = cnt; j < 8; j++,i++){
            if(i < list.size()){
                Node p = list.get(i);
                System.out.printf("%s %d %d\n",p.fileName,p.line,p.cnt);
            }             
        }
    }
}
class Node{
    public String fileName;
    public int line;
    public int cnt;
    public boolean flag;
    public Node(String fileName,int line,int cnt){
        this.fileName = fileName;
        this.line = line;
        this.cnt = cnt;
        this.flag = false;
    }
}

全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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