题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <cstdint> #include <iostream> #include <string> using namespace std; int isHuiWen(string str, int i, int j) { int length = -1; while (i >= 0 && j < str.size()) { if (str[i] != str[j]) { length = j - i - 1; break; } length = j - i + 1; i--; j++; } return length; } int main() { string inp; cin >> inp; int N = inp.size(); int maxLength = INT32_MIN; for (int i = 0; i < N - 1; i++) { maxLength = max(maxLength, isHuiWen(inp, i, i)); maxLength = max(maxLength, isHuiWen(inp, i, i+1)); } cout << maxLength; } // 64 位输出请用 printf("%lld")
两侧扩展
#华为机试#华为OD机测试题 文章被收录于专栏
个人练习专栏