"Huawei OJ" "069-Simple error logging"

Source: Internet
Author: User

"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "069-Simple Error Record" "Project download" topic description
开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。处理:    1、 记录最多8条错误记录,循环记录,对相同的错误记录(净文件名称和行号完全匹配)只记录一条,错误计数增加;    2、 超过16个字符的文件名称,只记录文件的最后有效16个字符;    3、 输入的文件可能带路径,记录文件名称不能带路径。
Enter a description
一行或多行字符串。每行包括带路径文件名称,行号,以空格隔开。
Output description
将所有的记录统计并将结果输出,格式:文件名 代码行数 数目,一个空格隔开,如:
Input example
E:\V1R2\product\fpgadrive.c   1325
Output example
fpgadrive.c 1325 1
Algorithm implementation
ImportJava.util.ArrayList;ImportJava.util.Scanner;/** * Author: Wang Junshu * time:2016-04-24 13:28 * CSDN:HTTP://BLOG.CSDN.NET/DERRANTCM * github:https://github.com/wang-ju N-chao * declaration:all rights Reserved!!! */ Public  class Main {    Private Static  class Error {        PrivateString name;Private intLinePrivate intCount@Override         PublicStringtoString() {returnName +" "+ Line +" "+ count; }    } Public Static void Main(string[] args) {Scanner input =NewScanner (system.in); arraylist<error> errors =NewArraylist<> (); while(Input.hasnext ()) {String name = Input.next ();intnum = Input.nextint (); Error record =NewError (); Name = Name.substring (Name.lastindexof ("\\") +1);if(Name.length () > -) {name = Name.substring (Name.length ()- -); }BooleanFlag =true;//Repeat inspection             for(Error error:errors) {if(Name.equals (error.name) && num = = error.line)                    {error.count++; Flag =false; }            }//represented as new record            if(flag)                {record.name = name;                Record.line = num; Record.count =1;            Errors.add (record); }} input.close ();//Up to 8 Error records        intj =0;if(Errors.size () >8) {j = errors.size ()-8; } for(; J < Errors.size (); j + +)        {System.out.println (Errors.get (j)); }    }}

"Huawei OJ" "069-Simple error logging"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.