本题将会给出
条报错信息,确切数字未知,您需要一直读入直到文件结尾;您也可以参考 牛客网在线判题系统使用帮助 获得更多的使用帮助。每条报错信息描述如下:
在一行上先输入一个长度为
的字符串
代表文件路径;随后,在同一行输入一个整数
代表行号。
文件路径的格式如题干所述,保证文件名不为空。
至多八行,每行先输出一个长度为
的字符串
,代表文件名;随后,在同一行输出错误行号、报错次数。
D:\oblemsinnowcoder 12 D:\nowcoderproblemsinnowcoder 12 D:\nowcoder\problemsinnowcoder 13 D:\oj\problemsinnowcoder 13
oblemsinnowcoder 12 2 oblemsinnowcoder 13 2
在这个样例中,这四条报错信息去除文件路径后,由于文件名长度均超过
个字符,故我们只保留最后
个字符,得到的文件名均为
。所以,我们将它们看作同一个文件,按照报错行号划分即可。
A:\aa 1 B:\b 1 C:\c 1 D:\d 1 E:\e 1 F:\f 1 G:\g 1 H:\h 1 I:\i 1 A:\aa 1
b 1 1 c 1 1 d 1 1 e 1 1 f 1 1 g 1 1 h 1 1 i 1 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
import sys
# 接收输入
def in_put(input_list : list):
for lines in sys.stdin.read().splitlines():
if lines != " " :
input_list.append(lines.split(" "))
return input_list
# 处理输入
def process_input(input_list : list):
for i in range(len(input_list)):
n = input_list[i][0].rfind("\\")
if len(input_list[i][0][n+1:]) >= 16:
input_list[i][0] = input_list[i][0][-16:]
else:
input_list[i][0] = input_list[i][0][n+1:]
return input_list
# 统计错误信息
"""这里用字典更好懒得改了"""
def record_error(input_list : list):
error_list = []
x = 1
for inputs in input_list:
if inputs not in error_list:
error_list.append(inputs)
error_list.append(1)
else:
x = error_list.index(inputs)
error_list[x+1] = error_list[x+1] + 1
if len(error_list) > 16:
del error_list[0:len(error_list)-16]
y = 1
error_str = ""
for errors in error_list:
if y % 2 != 0:
error_str = error_str.strip(" ") + str(errors[0]) + " " + str(errors[1])
y = y + 1
else:
error_str = error_str.strip(" ") + " " + str(errors) + "\n"
y = y + 1
return error_str
if __name__ == '__main__':
input_list = []
error_str = ""
input_list = in_put(input_list)
input_list = process_input(input_list)
error_str = record_error(input_list)
print(error_str[0:-1])
import sys
result_data = {} #{():1,():2}
for line in sys.stdin:
x, y = line.strip("\n").split(" ")
word = x.split("\\")[-1]
result = word if len(word)<=16 else word[-16:]
result_key = (result,y)
if result_data.get(result_key,0) == 0:
result_data[result_key] = 1
else:
result_data[result_key] += 1
for idx,items in enumerate(result_data):
if idx >= len(result_data) - 8:
print(items[0],items[1],result_data.get(items),sep=" ")
else:
pass
import sys
from collections import Counter
data = []
real_data=[]
for line in sys.stdin:
a = line.strip().split("\\")[-1]
data.append(a)
# 遍历data 只保留字母部分16个字符
for i in data:
# 找到字母部分
a=i.split(" ")[0][-16::]
# 找到数字部分
num=i.split(" ")[1]
# 拼接
item=a+" "+num
real_data.append(item)
# 此处可作为后续次数获取
count = dict(Counter(real_data))
# 列表去重
real_data=list(dict.fromkeys(real_data))
# 只保最后8条记录,如何实现?
# 去重后的 后8条数据 则为目标数据
real_data=real_data[-8::]
# 去先前字典中get 出现的字数
for i in real_data:
#找到次数
num=str(count.get(i))
print(i+" "+num) import sys
lines = [line.strip() for line in sys.stdin if line.strip()]
haxi={}
filename=[]
for i in range(len(lines)):
x,y=map(str,lines[i].split())
string=list(x.replace(':','').split('\\'))
length=len(string[len(string)-1])
S=string[len(string)-1]
if length > 16:
app = S[-16:] + ' ' + y
else:
app = S + ' ' + y
if app in haxi:
haxi[app] += 1
else:
haxi[app] = 1
if app not in filename:
filename.append(app)
if len(filename) <= 8:
for key in filename:
print(f'{key} {haxi[key]}', end='\n')
else:
for key in filename[-8:]:
print(f'{key} {haxi[key]}', end='\n') import sys
# for line in sys.stdin:
# a = line.split()
# print(int(a[0]) + int(a[1]))
count = {}
while True:
try:
path, row_id = input().split()
path_split = path.split("\\")
file_name = path_split[-1][-16:]
# print(file_name)
key = f"{file_name}_{row_id}"
if key not in count:
count[key] = 0
count[key] += 1
except:
break
# print(count)
for k, v in list(count.items())[-8:]:
key_split = k.split("_")
print(key_split[0] + " " + key_split[1] +" " + str(v)) import sys
inps = {}
for line in sys.stdin:
l = line.strip('\n')
if len(l) == 0:
continue
p, error_type = l.split(' ')
file_name = p.split("\\")[-1][-16:]
rec = f'{file_name} {error_type}'
if rec in inps:
inps[rec] += 1
else:
inps[rec] = 1
oups = []
for k, v in inps.items():
oups.append(f'{k} {v}')
for oup in oups[-8:]:
print(oup)
import sys
e = {}
for line in sys.stdin:
x, y = line.split()
# 注意:为了查找反斜杠,需要使用双反斜杠 '\\'
pos = x.rfind('\\')
if len(x[pos+1:]) <= 16:
s = x[pos+1:]
else:
s = x[-16:]
key = s + ' ' + y
if key not in e:
e[key] = 1
else:
e[key] += 1
for key in list(e.keys())[-8:]:
print(f'{key} {e[key]}') import sys
res = {}
while True:
try:
line = sys.stdin.readline().strip()
if not line:
res = list(res.items())[-8:]
for i in res:
print(f"{i[0][0]} {i[0][1]} {i[1]}")
break
line = line.split()
name, row = line
name = name.split('\\')[-1][-16:]
if (name, row) not in res:
res[(name, row)] = 1
else:
res[(name, row)] += 1
except:
break import sys
erro_dict, erro_list = {}, []
for line in sys.stdin:
route, row = line.split()
name = route.split('\\')[-1][-16:]
if name + row not in erro_dict:
erro_dict[name + row] = 1
erro_list.append((name, row))
else:
erro_dict[name + row] += 1
for i in erro_list[-8:]:
print(i[0], i[1], erro_dict[i[0] + i[1]])
import sys
inPut=[]
res=[]
for line in sys.stdin:
if not line.strip() in inPut:
inPut.append(line.strip())
#print(inPut)
times=[0]*len(inPut)
for i in range(len(inPut)):
last=inPut[i].split('\\')[-1].split(' ')
row=last[1]
if len(last[0])<=16:
name=last[0]
else:name=last[0][len(last[0])-16:len(last[0])]
record=str(name)+' '+str(row)
if not record in res:
res.append(record)
times[res.index(record)]=1
else:
times[res.index(record)]+=1
#print(res)
if len(res)<=8:
for i in range(len(res)):
print(res[i]+' '+str(times[i]))
else:
for i in range(len(res)-8,len(res)):
print(res[i]+' '+str(times[i])) import sys
paths = []
paths_num = {}
for line in sys.stdin:
path, row_num = line.split()
path = path.split("\\")[-1][-16:]
if path + ' ' + row_num not in paths_num.keys():
paths.append(path + ' ' + row_num)
paths_num[path + ' ' + row_num] = 1
else:
paths_num[path + ' ' + row_num] += 1
if len(paths) > 8:
start = len(paths) - 8
else:
start = 0
for i in range(start, len(paths)):
print(paths[i] + ' ' + str(paths_num[paths[i]])) files = {}
out = []
while True:
try:
s = input()
path, line = s.split(' ')
filename = path.split('\\')[-1][-16:]
key = f'{filename} {line}'
files.setdefault(key, 0)
files[key] += 1
# 记录最后输出的八个文件
if key not in out:
out.append(key)
except:
break
for k in out[-8:]:
print(k, files[k])