题解 | #【模板】循环队列#

【模板】循环队列

https://www.nowcoder.com/practice/0a3a216e50004d8bb5da43ad38bcfcbf

s = input().split()
n = int(s[0])
num = int(s[1])
st = []

for i in range(num):
    l = input().split(' ')
    if l[0]=='push':
        if len(st) < n:
            st.append(int(l[1]))
        else:
            print('full')
    elif st == []:
        print('empty')
    else :
        if l[0]=='pop':
            print(st.pop(0))
        elif l[0]=='front':
            print(st[0])

注意处理输入的时候要split 否则就是一整个的string了

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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