Find the length of the longest substring in the given string s that is the same in reverse.
As an example, if the input was “I like racecars that go fast”, the substring (racecar) length would be 7.
If the length of the input string is 0, the return value must be 0.
#include <string.h>
#include <stdio.h>
int longest_palindrome(const char *s)
{
int i,j=0,max=0,len=(int)strlen(s),cnt=0,t,p;
printf("string=%s\n",s);
if(len==1)
return 1;
//特殊情况判断
for(i=0;i<len;i++)
{
for(j=len-1;j>i;j--)
{
//两层循环
if(s[i]==s[j] && j-i>max)
{
cnt=0;
printf("i=%d j=%d\n",i,j);
t=i,p=j;
while(p-t>=1 )
{
if(s[t++]==s[p--])
cnt+=2;
else
{
cnt=1;
break;
}
}
if((j-i+1)%2!=0)
cnt++;
printf("cnt=%d\n",cnt);
}
if(cnt>max)
max=cnt;
}
}
printf("max =%d\n",max);
printf("\n\n\n");
return max; //your code here
}