当前位置:网站首页>牛客 HJ19 简单错误记录
牛客 HJ19 简单错误记录
2022-07-31 15:58:00 【顧棟】
描述
开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。
处理:
1、 记录最多8条错误记录,循环记录,最后只用输出最后出现的八条错误记录。对相同的错误记录只记录一条,但是错误计数增加。最后一个斜杠后面的带后缀名的部分(保留最后16位)和行号完全匹配的记录才做算是“相同”的错误记录。
2、 超过16个字符的文件名称,只记录文件的最后有效16个字符;
3、 输入的文件可能带路径,记录文件名称不能带路径。也就是说,哪怕不同路径下的文件,如果它们的名字的后16个字符相同,也被视为相同的错误记录
4、循环记录时,只以第一次出现的顺序为准,后面重复的不会更新它的出现时间,仍以第一次为准
数据范围:错误记录数量满足 1 ≤ n ≤ 100 1 \le n \le 100 1≤n≤100 ,每条记录长度满足 1 ≤ l e n ≤ 100 1 \le len \le 100 1≤len≤100
输入描述:
每组只包含一个测试用例。一个测试用例包含一行或多行字符串。每行包括带路径文件名称,行号,以空格隔开。
输出描述:
将所有的记录统计并将结果输出,格式:文件名 代码行数 数目,一个空格隔开,如:
示例1
输入:
D:\zwtymj\xccb\ljj\cqzlyaszjvlsjmkwoqijggmybr 645
E:\je\rzuwnjvnuz 633
C:\km\tgjwpb\gy\atl 637
F:\weioj\hadd\connsh\rwyfvzsopsuiqjnr 647
E:\ns\mfwj\wqkoki\eez 648
D:\cfmwafhhgeyawnool 649
E:\czt\opwip\osnll\c 637
G:\nt\f 633
F:\fop\ywzqaop 631
F:\yay\jc\ywzqaop 631
D:\zwtymj\xccb\ljj\cqzlyaszjvlsjmkwoqijggmybr 645
输出:
rzuwnjvnuz 633 1
atl 637 1
rwyfvzsopsuiqjnr 647 1
eez 648 1
fmwafhhgeyawnool 649 1
c 637 1
f 633 1
ywzqaop 631 2
说明:
由于D:\cfmwafhhgeyawnool 649的文件名长度超过了16个字符,达到了17,所以第一个字符'c'应该被忽略。
记录F:\fop\ywzqaop 631和F:\yay\jc\ywzqaop 631由于文件名和行号相同,因此被视为同一个错误记录,哪怕它们的路径是不同的。
由于循环记录时,只以第一次出现的顺序为准,后面重复的不会更新它的出现时间,仍以第一次为准,所以D:\zwtymj\xccb\ljj\cqzlyaszjvlsjmkwoqijggmybr 645不会被记录。
java实现
package nowcoder.x1x;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
public class HJ019 {
public static void main(String[] arge) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str;
LinkedHashMap<String, Integer> linkedHashMap = new LinkedHashMap<>();
while (null != (str = bf.readLine())) {
int i1 = str.lastIndexOf(" ");
int i2 = str.lastIndexOf("\\");
String key = (i1 - i2) > 16 ? str.substring(i1 - 16) : str.substring(i2 + 1);
linkedHashMap.put(key, linkedHashMap.getOrDefault(key, 0) + 1);
}
int count = 0;
for (String key : linkedHashMap.keySet()) {
count++;
if (count > (linkedHashMap.size() - 8)) {
System.out.println(key + " " + linkedHashMap.get(key));
}
}
}
}
边栏推荐
- 2020 WeChat applet decompilation tutorial (can applet decompile source code be used)
- What is the difference between BI software in the domestic market?
- 多主复制的适用场景(1)-多IDC
- 6-22 Vulnerability exploit - postgresql database password cracking
- 更新数据表update
- 11 pinia使用
- Why don't you make a confession during the graduation season?
- 2022年必读的12本机器学习书籍推荐
- Use of radiobutton
- SHELL内外置命令
猜你喜欢
.NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world
11 pinia use
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
全新宝马3系上市,安全、舒适一个不落
对话庄表伟:开源第一课
【7.29】代码源 - 【排列】【石子游戏 II】【Cow and Snacks】【最小生成数】【数列】
Graham‘s Scan法求解凸包问题
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
radiobutton的使用
Why is the field of hacking almost filled with boys?
随机推荐
Implementing distributed locks based on Redis (SETNX), case: Solving oversold orders under high concurrency
Browser's built-in color picker
mongo enters error
How does automated testing create business value?
2.索引及调优篇【mysql高级】
苹果官网样式调整 结账时产品图片“巨大化”
11 pinia使用
外媒所言非虚,苹果降价或许是真的在清库存
01 Encounter typescript, build environment
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
Oracle dynamically registers non-1521 ports
The 2nd China PWA Developer Day
t-sne 数据可视化网络中的部分参数+
深度学习机器学习理论及应用实战-必备知识点整理分享
After Grafana is installed, the web opens and reports an error
Codeforces Round #796 (Div. 2)(A-D)
软件实现AT命令操作过程
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
leetcode303 Weekly Match Replay
Applicable scenario of multi-master replication (2) - client and collaborative editing that require offline operation