Problem Description
给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.
回文就是正反读都是一样的字符串,如aba, abba等
 

 

Input
输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c...y,z组成的字符串S
两组case之间由空行隔开(该空行不用处理)
字符串长度len <= 110000
 

 

Output
每一行一个整数x,对应一组case,表示该组case的字符串中所包含的最长回文长度.
 

 

Sample Input
aaaa abab
 

 

Sample Output
4 3
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1358 1686 3336 3065 3746 
 
manacher模板题。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#define MAX 110000
using namespace std;

int manacher(char *s,int len) {
    char t[MAX * 2 + 2] = {'@','#'};
    int p[MAX * 2 + 2];
    int c = 2;
    for(int i = 0;i < len;i ++) {
        t[c ++] = s[i];
        t[c ++] = '#';
    }
    int rp = 0,rrp = 0,ml = 0;
    for(int i = 1;i < c;i ++) {
        p[i] = i < rrp ? min(p[rp - (i - rp)],rrp - i) : 1;
        while(t[i + p[i]] == t[i - p[i]]) {
            p[i] ++;
        }
        if(rrp < i + p[i]) {
            rrp = i + p[i];
            rp = i;
        }
        if(ml < p[i]) {
            ml = p[i];
        }
    }
    return ml - 1;
}
int main() {
    char s[MAX + 1];
    while(~scanf("%s",s)) {
        printf("%d\n",manacher(s,strlen(s)));
    }
}