while True:
try:
s=input()
ll=len(s)
#print(ll)
num=0
for i in range(1,ll):
#求以i-1和i为中心的偶数对称子串长度
low=i-1
high=i
while(low>=0 and high<ll and s[low]==s[high]):
low-=1
high+=1
if(high-low-1>num):
num=high-low-1
#求以i为中心的奇数对称子串长度
low=i-1
high=i+1
while(low>=0 and high<ll and s[low]==s[high]):
low-=1
high+=1
if(high-low-1>num):
num=high-low-1
if(num):
print(num)
except:
break
华为机试——字符串运用-密码截取
最新推荐文章于 2025-05-22 11:08:08 发布