题解 | #【模板】栈#ififif

【模板】栈

https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf

n=int(input())
z=[]
for i in range(n):
    s=input()
    if s.startswith("push"):
        s=s.split()
        x=int(s[1])
        z.append(x)
    if s=="pop":
        if z==[]:
            print("error")
        else:
            print(z.pop()) 
    if s=="top":
        if z==[]:
            print("error")
        else:
            print(z[-1])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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