题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
#include <stdio.h>
#include <string.h>
#define max(x,y) ((x>y)?x:y)
int main() {
char str[351]={0};
scanf("%s",str);
int lmax=0;
int lc=0;
for(int i=0;i<strlen(str);i++)
{
for(int j=(strlen(str)-1);j>=i;j--)
{
int a,b;
a=i;
b=j;
while(str[a]==str[b])
{
if((a==b-1)||(a==b))
{
lc=lc+b-a+1;
lmax=max(lc,lmax);
break;
}
a++;
b--;
lc=lc+2;
}
lc=0;
}
}
printf("%d",lmax);
}

