题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <iostream>
using namespace std;
bool is_password(const char* begin, const char* end) {
while (*begin == *end) {
++begin;
--end;
}
return begin >= end;
}
int main() {
string text;
while (cin >> text) {
int max_length = 1;
for (size_t i = 0; i < text.size(); ++i) {
const char c = text[i];
string::size_type pos = text.size();
do {
pos = text.find_last_of(c, pos - 1);
if (is_password(&text[i], &text[pos])) {
int length = pos - i + 1;
if (length > max_length) {
max_length = length;
}
}
} while (pos > i);
}
cout << max_length << endl;
};
}
// 64 位输出请用 printf("%lld")

