最长对称子串:
给出一个字符串,求出它的最长的对称的子串的长度
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
usingnamespace std;
intmain()
{
string str;
int max,maxx=1;
getline(cin,str);
int len=str.length();
for(int i=1; i<len-1; i++)
{
max=1;
int x=i-1;
int y=i+1;
while(x>=0&&y<len)
{
if(str[x]==str[y])
{
x--;
y++;
max+=2;
}
else
break;
}
if(max>maxx)
maxx=max;
}
for(int i=0; i<len-1; i++)
{
max=0;
int x=i;
int y=i+1;
while(x>=0&&y<len)
{
if(str[x]==str[y])
{
x--;
y++;
max+=2;
}
else
break;
}
if(max>maxx)
maxx=max;
}
printf("%d\n",maxx);
return 0;
}