题解 | 【模板】栈的操作
【模板】栈的操作
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))
查看10道真题和解析
