题目大意:
给你一行字符串,总共n个(1<=n<=1000),问你这串字符串中,最长的字符回文串是什么?
input:
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
output:
ArozaupalanalapuazorA
【参考程序】:
#include<iostream>
using namespace std;
char str[1001];
int n,start,maxs;
void func(int s,int t)
{
while (s>1 && t<n)
{
if (str[s-1]!=str[t+1]) break;
s--;t++;
}
if (t-s+1>maxs)
{
maxs=t-s+1;
start=s;
}
}
int main()
{
freopen("1297.in","r",stdin);
freopen("1297.out","w",stdout);
char c;n=0;
while (scanf("%c",&c)!=EOF)
{
n++;str[n]=c;
}
maxs=0;
for (int i=1;i<=n;i++) func(i,i);
for (int i=2;i<=n;i++)
if (str[i-1]==str[i])
func(i-1,i);
for (int i=start;i<=start+maxs-1;i++)
printf("%c",str[i]);
printf("\n");
return 0;
}