###中心扩展法 参考资料

#include<stdio.h>
#include<string.h>

int subpalidromelen(char *chsIn, int i);

int main(int argc, char const *argv[])
{
    char str_in[999];
    char chs[999];
    while ( scanf("%s", str_in) != EOF )
    {
        //将原有字符串间隔加入#,防止偶数字符串的回文数不好计算。奇数+偶数=奇数
        memset(chs, 0X00, sizeof(chs));
        for (int i = 0; i < strlen(str_in); i++)
        {
            strcat(chs, "#");
            sprintf(chs+strlen(chs), "%c", str_in[i]);
        }
        
        strcat(chs, "#");

        int maxHWlen = 0;
        for (int i = 0; i < strlen(chs); i++)
        {
            //中心扩展函数
            if (subpalidromelen(chs, i) > maxHWlen)
            {
                maxHWlen = subpalidromelen(chs, i);
            }
            
        }
        printf("%d\n", maxHWlen);
    }
    
    return 0;
}

int subpalidromelen(char *chsIn, int i)
{
    int len = 0;

    for (int k = 0; k <=i ; k++)
    {
        if (chsIn[i - k] == chsIn[i + k])
        {
            len++;
        }
        else
        {
            break;
        }       
    }
    return len - 1;
}