Source title: https://vjudge.net/problem/UVA-11475
Very standard palindrome string problem (why always in some places weird wrong ..)
#include <iostream> #include <stdio.h> #include <cstring> #define LCOAL #define maxn 100005 using namespace std; char s[maxn], ma[maxn << 1]; int mp[maxn << 1]; //注意开双倍 // code reference oiwiki int Manacher ( char S []) { int mal = 0; ma[mal++] = '#'; //首位为# int len = strlen(s); for (int i = 0; i < len; ++i) is [mal ++] = s [i] is [mal ++] = ' # ' ; mp[0] = 0; for (int i = 1, l = 0, r = -1; i < mal; ++i) { mp[i] = i > r ? 1 : min(mp[l + r - i], r - i); while (i - mp[i] >= 0 && i + mp[i] < mal && ma[i - mp[i]] == ma[i + mp[i]]) mp[i]++; if (i + mp[i] == mal) return i - mp[i]; if (i + mp[i] > r) { L = I - Mp [I]; R = I Tasu Mp [I]; } } } int main () { int t; while (~scanf("%s", s)) { printf("%s", s); t = Manacher(s); for (int i = t; i > 0; --i) { if (ma[i] != '#') putchar(ma[i]); } putchar('\n'); } }