题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <iostream> #include <stdexcept> using namespace std; int main() { string str; getline(cin, str); int maxc = 0; int sy; for (int i = 0; i < str.length(); i++) { sy = i; int pos = 1, count = 0; while (str[i] == str[i + pos]) { count += 2; if (i == 0 || i + pos == str.length()-1) break; i --; pos += 2; } i = sy; pos =1; maxc = max(count, maxc); count =0; while (str[i - pos] == str[i + pos]) { if (count == 0) count = 1; count += 2; if (i - pos <= 0 || i + pos >= str.length()-1) break; pos ++; } maxc = max(count, maxc); } cout << maxc << endl; }