题解 | 【模板】队列操作

【模板】队列操作

https://www.nowcoder.com/practice/1137c8f6ffac4d5d94cc1b0cb08723f9

from collections import deque

# 初始化
queue = deque()

q = int(input())

for _ in range(q):
    operate = input().split()

    if operate[0] == '1':
        x = int(operate[1])
        queue.append(x)

    if operate[0] == '2':
        if queue:
            queue.popleft()
        else:
            print('ERR_CANNOT_POP')
    
    if operate[0] == '3':
        if queue:
            print(queue[0])
        else:
            print('ERR_CANNOT_QUERY')

    if operate[0] == '4':
        print(len(queue))
        


面试刷题-ACM 文章被收录于专栏

面试刷题-ACM格式

全部评论

相关推荐

叁六玖:真绷不住了,可能它想逗逗你,让你开心一下
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务