括号配队检测a

t = input()
a = 0
Left_bracket_Z=0
Right_bracket_Z=0
for i in t:
if i== '(':
a+=1
elif i== ')':
if a>0:
a-=1
else:
print("配对不成功")
break
elif i=='[':
Left_bracket_Z+=1
elif i==']':
Right_bracket_Z+=1
else:
if a!=0:
print("配对不成功")
elif Left_bracket_Z!=Right_bracket_Z:
print("配对不成功")
else:
print("配对成功")

posted @ 2020-03-23 21:18  Xiao_kong  阅读(162)  评论(0编辑  收藏  举报