题解 | 简单错误记录
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import sys """ 知识点: 1. 转义字符\的处理 2. 如何自定义循环例如从列表的最后一个向前遍历? """ # 存储输入 count = sys.stdin.read().strip().split("\n") # count = count[:len(count)-1] # print(count) # ['D:\\oblemsinnowcoder 12', 'D:\\nowcoderproblemsinnowcoder 12', 'D:\\nowcoder\\problemsinnowcoder 13', 'D:\\oj\\problemsinnowcoder 13'] count2 = [] # 用来存储中间结果 # 去掉多余信息 # 遍历所有报错地址 for i in range(len(count)): str1 = str(count[i]) # 遍历每个报错地址的字符 j = 0 while '\\' in str1: if str1[j] == '\\' : str1 = str1[j+1:] j = 0 j += 1 # print(str1) for g in range(len(str1)): tag = 0 # 记录空格位置 if str1[g] == ' ': tag = g # 如果大于16则截断 if len(str1[:g]) > 16: str1 = str1[tag-16:] break # print(str1) count2.append(str1) # print(count2) # ['oblemsinnowcoder 12', 'oblemsinnowcoder 12', 'oblemsinnowcoder 13', 'oblemsinnowcoder 13'] # 输出不重复的报错地址 t = [] # 计数器 count3 = [] for i in range(len(count2)): if count2[i] not in count3: count3.append(count2[i]) t.append(1) else: for p in range(len(count3)): if count2[i] == count3[p]: t[p] += 1 # 输出最后8条 # print(count3) # ['oblemsinnowcoder 12', 'oblemsinnowcoder 13'] if len(count3) > 8: count3 = count3[-8:] t = t[-8:] for i in range(len(count3)): print(count3[i],t[i],sep=' ')