题解 | 完成括号匹配
m1 = input() m = m1 #把所有能匹配的通过while循环去掉,剩下的就是不匹配的 while "[]" in m: m = m.replace("[]", "") #统计不匹配的 sum1 = m.count("[") sum2 = m.count("]") #补全 for n in range(sum1): m1 = m1 + "]" for n in range(sum2): m1 = "[" + m1 print(m1)
m1 = input() m = m1 #把所有能匹配的通过while循环去掉,剩下的就是不匹配的 while "[]" in m: m = m.replace("[]", "") #统计不匹配的 sum1 = m.count("[") sum2 = m.count("]") #补全 for n in range(sum1): m1 = m1 + "]" for n in range(sum2): m1 = "[" + m1 print(m1)
相关推荐