1.删除字符中连续字符长度大于2的字符,在消除的字符串上继续消除。
(1)测试样例
input1:abbbssa[题目给出]
output1:assa
input2:sbbbssa[自己想的]
output2:a
ac代码:
def remove_str(s):
for i in range(len(s)-1):
if s[i] != s[i+1]: #找到和s[0]不相等的位置,就是打破连续相等现状的位置
return s[i+1:]
return None
while(True):
try:
tmp_str = input().strip()
c_count = []
result_str = []
i = 0
while(i < len(tmp_str)):
if i+1<len(tmp_str) and i+2 < len(tmp_str) and tmp_str[i] == tmp_str[i+1] and tmp_str[i+1] == tmp_str[i+2]:
lat_str = remove_str(tmp_str[i+1:]) # 去除重复的后半段字符串
for_str = tmp_str[:i] # 前半段
if lat_str:
tmp_str = for_str + lat_str # 修改tmp_str