str1=raw_input()+'x'
ans=0
while str1 != 'x':i=0
while str1[i] != 'x':
if str1[i]=='(' and str1[i+1]==')':
str1=str1[:i]+str1[i+2:]i-=1
i+=1
ans+=1
print ans
原题来自于:https://www.nowcoder.com/test/question/a2d5b1875bb0408384278f40d1f236c9?pid=8246915&tid=12781653
本文提供了一段Python代码,用于解决一个简单的字符串处理问题:从输入的字符串中去除成对出现的括号('()'),直到没有这样的括号对为止,并统计总共移除了多少对括号。此算法通过循环遍历字符串并检查相邻字符是否构成括号对来实现。
3971

被折叠的 条评论
为什么被折叠?



