#最长回文子串
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507?tpId=37&&tqId=21308
#include <stdio.h> int func (const char *a) { int cnt = 0, des = 0; int len = 0; char *p = a + 1; while (*p != '\0') {//*(p+1)!='\0' if (*p == *(p+1)) { //even cnt = 0; des = p - a; for (int i = 0; i < des +1; i++) { if (*(p+1+i) != *(a+des-i)) { break; } cnt += 2; } len = len > cnt ? len : cnt; } if (*(p-1) == *(p+1)) { //odd cnt = 1; des = p - a; for (int i = 0; i < des + 1; i++) { if (*(p+1+i) != *(a+des-1-i)) { break; } cnt += 2; } len = len > cnt ? len : cnt; } p++; } return len; } int main() { char arr[1024] = {0}; while (EOF != scanf("%s", arr)) { printf("%d\n", func(arr)); } return 0; }