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