题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
import sys def isas(str): for i in range(len(str)//2): if str[i] == str[-i-1]: pass else: return False return True for line in sys.stdin: a = line.strip() dp = [1 for i in range(len(a))] for i in range(1,len(a)): max_l = 1 for j in range(dp[i-1],-1,-1): get = False if i>=j+1: if a[i]==a[i-j-1]: if j > 1: if isas(a[i-j:i]): get=True else: get=True if get: this=j+2 if this> max_l: max_l=this else: if a[i]==a[i-1]: this=2 if this> max_l: max_l=this dp[i] = max_l print(max(dp))