← 返回题库
中级

实现临时停播高优先级指令

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    import time
    class CommandQueue:
        PRIORITY = {'____':____,'____':____,'____':____,'____':____}
        def __init__(____):
            self.queue = []
        def push(____):
            self.queue.append(____)
            self.queue.sort(key=lambda x: self.PRIORITY.get(x.get(____),____))
        def pop(____):
            return self.queue.pop(____) if self.queue else None
        def peek(____):
            return self.queue[____] if self.queue else None
    q = CommandQueue()
    commands = [
        {'____':'____','____':'____','____':'____','____':'____','____':____},
        {'____':'____','____':'____','____':'____','____':'____','____':____},
        {'____':'____','____':'____','____':'____','____':'____','____':____},
        {'____':'____','____':'____','____':'____','____':'____','____':____},
    ]
    for cmd in commands:
        q.push(____)
    print(____)
    while q.queue:
        cmd = q.pop()
        print(____)

示例

输入
solve()
期望输出
Command queue (sorted by priority):
  [emergency] CMD-002 pause_playback -> SCR-0001
  [emergency] CMD-004 resume_playback -> SCR-0001
  [high] CMD-003 update_creative -> SCR-0001
  [normal] CMD-001 update_schedule -> SCR-0001
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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