题解 | 【模板】栈的操作

【模板】栈的操作

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

from sys import stdin
from random import randint
input = lambda: stdin.readline().strip()
# read1 = stdin.read().split()
# idx = 1
l = []
for _ in range(int(input())):
    x = input().split()
    if x[0] == "push":
        l.append(x[1])
    elif x[0] == "pop":
        try:
            l.pop()
        except:
            print("Empty")
    elif x[0] == "query":
        try:
            print(l[-1])
        except:
            print("Empty")
    else:
        print(len(l))


全部评论

相关推荐

axiom15:校友,我感觉你这个简历去华子暑期实习随便去了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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