题解 | #简单错误记录#

简单错误记录

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

import java.util.Scanner;

public class Main { //由于仍以第一次出现的时间为准的循环记录,拟采用窗口的方式实现。 public static void main(String[] args) { //输入 Scanner scanner=new Scanner(System.in); MyError myError[]=new MyError[100];//储存错误记录 for (int i = 0; i < 100; i++) { myError[i]=new MyError(); } int i=0;//窗口结束位置

    //填入第一个记录
    String line=scanner.nextLine();
    String tmp1[]= line.split(" ")[0].split("\\\\");
    int intTmp= Integer.parseInt(line.split(" ")[1]);
    //裁剪文件名
    if (tmp1[tmp1.length-1].length()>16)
        tmp1[tmp1.length-1]=tmp1[tmp1.length-1].substring(tmp1[tmp1.length-1].length()-16,
                tmp1[tmp1.length-1].length());
    myError[i].setName(tmp1[tmp1.length-1]);
    myError[i].setLineCount(intTmp);
    myError[i].setCount(1);


    outter:while(scanner.hasNextLine()){
        line=scanner.nextLine();
        if (line.equals(""))break;
        String s=line.split(" ")[0];
        String tmp[]= s.split("\\\\");
        intTmp= Integer.parseInt(line.split(" ")[1]);
        //裁剪文件名
        if (tmp[tmp.length-1].length()>16)tmp[tmp.length-1]=tmp[tmp.length-1].substring(tmp[tmp.length-1].length()-16,tmp[tmp.length-1].length());
        for (int j = 0; j <= i; j++) {
            if (myError[j].getName().equals(tmp[tmp.length-1])
                    &&myError[j].getLineCount()==intTmp) {
                myError[j].setCount(myError[j].getCount()+1);
                continue outter;
            }
        }
        i++;
        myError[i].setName(tmp[tmp.length-1]);
        myError[i].setLineCount(intTmp);
        myError[i].setCount(1);
    }

    //输出窗口
    if (i>=8){
        for (int j = i-7; j <=i ; j++) {
            System.out.println(myError[j].getName()+" "+myError[j].getLineCount()+" "+myError[j].getCount());
        }
    }
    else{
        for (int j = 0; j <=i; j++) {
            System.out.println(myError[j].getName()+" "+myError[j].getLineCount()+" "+myError[j].getCount());
        }
    }
}

private static class MyError {
    String name="";
    int lineCount=0;
    int count=0;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLineCount() {
        return lineCount;
    }

    public void setLineCount(int lineCount) {
        this.lineCount = lineCount;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}

}

全部评论

相关推荐

浪子陪都:简历最优秀的地方放到了后面,国奖,校级奖学金这些是最亮眼的。说明你跟同级别的学生不一样。 建议台灯这个,PCB布局布线这个词汇不专业,业内是PCB Layout,第二,单片机的板子一般不用考虑SI,PI 都是低速信号,只要遵循3W原则就好了。 单片机的项目太low了,技能这块,你要看一下BOSS直聘的招聘要求,按照别人的要求写,一些关键词可以增加你简历被检索到的概率。 主修课程不用写,这个没有人去关注的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务