Str=input("")
Left_bracket=0
Left_bracket_Z=0
Right_bracket_Z=0
for i in Str:
if i== ‘(‘:
Left_bracket+=1
elif i== ‘)‘:
if Left_bracket>0:
Left_bracket-=1
else:
print("配对不成功")
break
elif i==‘[‘:
Left_bracket_Z+=1
elif i==‘]‘:
Right_bracket_Z+=1
else:
if Left_bracket!=0:
print("配对不成功")
elif Left_bracket_Z!=Right_bracket_Z:
print("配对不成功")
else:
print("配对成功")
原文:https://www.cnblogs.com/shizihao/p/15267431.html