//输入,并处理得到字符串s int p[1000], mx = 0, id = 0; memset(p, 0, sizeof(p)); for (i = 1; s[i] != '\0'; i++) { p[i] = mx > i ? min(p[2*id-i], mx-i) : 1; while (s[i + p[i]] == s[i - p[i]]) p[i]++; if (i + p[i] > mx) { mx = i + p[i]; id = i; } } //找出p[i]中最大的