题解 | 【模板】栈的操作

【模板】栈的操作

https://www.nowcoder.com/practice/cdf02ea916454957b575585634e5773a

stack=[]

n=int(input())
for i in range(n):
    operator=input().split()
    if operator[0]=="push":
        stack.append(operator[1])
    elif operator[0]=="pop":
        if stack:
            stack.pop()
        else:
            print("Empty")
    elif operator[0]=="query":
        if stack:
            print(stack[-1])
        else:
            print("Empty")
    elif operator[0]=="size":
        print(len(stack))

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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