对于输入的字符串,复制一个它的反串,求它们最大的公共子串
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
char str[1003];
char s2[1003];
int dp[1005][1005];
int main()
{
while( gets(str))
{
int n=strlen(str);
for(int i=n-1;i>=0;i--)
s2[i]=str[n-1-i];
dp[0][0]=0;
for(int l=0;l<n;l++)
dp[0][l]=dp[l][0]=0;
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
{
if(str[j-1]==s2[k-1]){dp[k][j]=dp[k-1][j-1]+1;}
else
dp[k][j]=0;
}
int max=1;
for(int u=1;u<=n;u++)
for(int s=1;s<=n;s++)
if(max<dp[u][s])max=dp[u][s];
cout<<max<<endl;
}
return 0;
}