← 返回题库
中级

实现下载历史记录与去重逻辑

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    class DownloadTracker:
        def __init__(____): self.history=set()
        def record(____):
            key=(____)
            if key in self.history: return False,'____'
            self.history.add(____); return True,'____'
        def user_downloads(____): return [s for u,s in self.history if u==uid]
    t=DownloadTracker()
    tests=[(____),(____),(____),(____)]
    print(____)
    for uid,sid in tests:
        ok,msg=t.record(____)
        print(____)
    print(____)

示例

输入
solve()
期望输出
Download tracking:
  USR-0001 -> SHR-00001: OK [recorded]
  USR-0001 -> SHR-00002: OK [recorded]
  USR-0001 -> SHR-00001: SKIP [already_downloaded]
  USR-0002 -> SHR-00001: OK [recorded]
USR-0001 downloads: ['SHR-00002', 'SHR-00001']
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码