题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <iostream> using namespace std; int main() { string s; cin>>s; int max_length=1; for (int i=1; i<s.size(); i++) { int low=i-1,high=i; while(low>=0 && high<s.size() && s[low]==s[high]) { low--; high++; } max_length=max(max_length,high-low-1); low=i-1; high=i+1; while (low>=0 && high<s.size() && s[low]==s[high]) { low--; high++; } max_length=max(max_length,high-low-1); } cout<<max_length<<endl; } // 64 位输出请用 printf("%lld")