小甲鱼课后作业列表ii 这么写行吗
s = input("请输入测试字符串:")
stack = []
a=0
for c in s:
if c == '(' or c == '[' or c == '{':
stack.append(c)
print(stack)
else:
if len(stack) == 0:
print("非法T_T")
break
if c==']'or c=='}'or c==')':
x=stack.pop()
if ==["(",")"]or==["{","}"]or ==["[","]"]:
print()
stack.insert(0,1)
a+=1
print(stack)
else:
print("非法T_T")
break
else:
b=1
else:
if len(stack) == a:
print("合法^o^")
else:
print("非法T_T") 中间的print是写代码时为了检验写的,忽略就好
页:
[1]