小红书笔试
第一题 倒卖战利品
s = input().strip()
# s = "a<<b((c)<)"
n = len(s)
stack = []
res = ""
for i in range(n):
if s[i]!="<" and not stack and s[i]!="(" and s[i]!=")":
res += s[i]
elif s[i]=="<" and not stack and s[i]!="(" and s[i]!=")":
if len(res)>0:
res = res[:len(res)-1]
else:
res = ""
elif s[i]=="(":
stack.append(s[i])
elif stack and s[i]==")":
stack.pop()
else:
continue
print(res)
查看13道真题和解析