小红书笔试

第一题  倒卖战利品
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)


#小红书##笔试题目#
全部评论

相关推荐

评论
点赞
3
分享

创作者周榜

更多
牛客网
牛客企业服务