回文串的判定条件:1、相邻两个字符相同;2、当前字符的前后两个字符相同
1、给定一个字符串,删除其中的回文串,使打印的字符串不包含回文字符
def deleteHuiwen(s):
tmp = ""
for i in range(len(s)):
if tmp == "":
tmp += s[i]
elif tmp[-1] == s[i]:
tmp = tmp[:-1]
elif len(tmp) > 1:
if tmp[-1] != s[i] and tmp[-2] == s[i]:
tmp = tmp[:-2]
else:
tmp += s[i]
else:
tmp += s[i]
i += 1
print (tmp)
2、给定一个字符串,删除部分字符串,使输出字符串中不包含回文串
def pohuaiHuiwen(s):
tmp = ""
for i in range(len(s)):
if tmp == "":
tmp += s[i]
if len(tmp) == 1 and tmp[-1] != s[i]:
tmp += s[i]
if len(tmp) >= 2 and tmp[-1] != s[i] and tmp[-2] != s[i]:
tmp += s[i]
i += 1
print (tmp)