AcWing 3693. 括号匹配(无思路硬写版) -- python
原题链接
简单
作者:
hosea
,
2024-07-24 20:35:10
,
所有人可见
,
阅读 8
import sys
s = input()
stack = []
for i in s:
if i in ["<", "(", "{", "["]:
stack.append(i)
else:
if len(stack) == 0:
print("no")
sys.exit(0)
a = stack.pop()
if a == "<" and i != ">":
print("no")
sys.exit(0)
if a == "(" and i != ")":
print("no")
sys.exit(0)
if a == "[" and i != "]":
print("no")
sys.exit(0)
if a == "{" and i != "}":
print("no")
sys.exit(0)
if len(stack):
print("no")
sys.exit(0)
else:
print("yes")