题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
import sys n = int(input()) acts = [] stack = [] for i in range(n): acts.append(input().split()) for act in acts: if act[0]=='push': stack.append(int(act[1])) elif act[0]=='pop': if len(stack)!=0: print(stack.pop()) else: print('error') elif act[0]=='top': if len(stack)!=0: print(stack[-1]) else: print('error')