题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import sys history, logs = [], {} while True: log = sys.stdin.readline().strip() try: name, line = map(str, log.split(" ")) except: break if len(name) > 16: name = name[-16:] if "\\" in name: name = name.split("\\")[-1] if f"{name} {line}" in logs: logs[f"{name} {line}"] += 1 else: logs[f"{name} {line}"] = 1 # if f"{name} {line}" in history: # break # history.append(f"{name} {line}") if len(logs) > 8: for i in range(len(logs) - 8, len(logs)): print(f"{list(logs.keys())[i]} {logs[list(logs.keys())[i]]}") else: for i in logs: print(f"{i} {logs[i]}")
可以说题目阐述不是太清楚。。。撞了很多次坑,说是循环,最多存八条...实际上不能全存进去一个缓存里拿一个重复的记录做结束循环的判断,干脆点就是空的回车就结束就满足了。