检查这个字符串是否回文
def check_huiwen(a):
str_len = len(a)
is_huiwen = True
for i in range(str_len - 1 // 2):
oa = str_len - 1 - i
if a[i] != a[oa] and i != oa:
is_huiwen = False
return is_huiwen
while True:
try:
a = input()
a_len = len(a)
max_len = 0 #回文串最大长度
if a_len >= 2:
for i in range(a_len - 1):
if max_len < a_len - i:#只需要判断长度大于max_len的
for j in range(max_len, a_len - i):
if check_huiwen(a[i:i + j + 1]) == True:
if max_len < j + 1:
max_len = j + 1
print(max_len) except:break