题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <iostream> #include <string> #include <vector> using namespace std; // 直接滑动窗口也不是不能做,就是可能没办法全部AC // 从中间扩散开 int main() { string strs1; getline(cin,strs1); int maxLen = 1; for(int i = 1;i<strs1.size();i++) { int tempLen = 0; int k = 0; // 偶子串 while(i-k>=0 && i+k+1 < strs1.size()) { if(strs1[i-k] == strs1[i+k+1]) { k++; tempLen += 2; } else{break;} } if(tempLen > maxLen) { maxLen = tempLen; } k = 1; tempLen = 1; while(i-k >= 0 && i+k < strs1.size()) { if(strs1[i-k] == strs1[i+k]) { k++; tempLen += 2; } else {break;} } if(tempLen > maxLen) { maxLen = tempLen; } } cout << maxLen << endl; } // 64 位输出请用 printf("%lld")