额,输出调试信息后发现 tmp 和 stack[-1] 的地址竟然是一样的,为甚么啊
from sys import stdin
stack = []
t = int(input())
for _ in range(t):
n = int(input())
for __ in range(n):
cmd = stdin.readline()
if cmd == "PUSH\n":
stack.append([])
elif cmd == "DUP\n":
stack.append(stack[-1])
elif cmd == "UNION\n":
tmp = stack.pop()
stack[-1] += [i for i in tmp if i not in stack[-1]]
elif cmd == "INTERSECT\n":
tmp = stack.pop()
stack[-1] = [i for i in stack[-1] if i in tmp]
else: # ADD 出错了,相当于做了 x.append(x) 的事
tmp = stack.pop()
print(id(tmp), id(stack[-1])) # 明明 len(stack) = 2,为甚么这两个地址一样啊
# 难道 pop() 有问题?
if (tmp not in stack[-1]): stack[-1].append(tmp)
print(len(stack[-1]))
print("***")