2 asdf adfsd 123abc abc123abc
3 6
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main(int argc, char* argv[])
{
int T;
scanf("%d",&T);
while(T--)
{
char x[1000],y[1000];
int r[1000],s[1000];
int
Lx,Ly,i,j;
memset(s,0,sizeof(s));
memset(r,0,sizeof(r));
scanf("%s%s",x,y);
Lx=strlen(x);
Ly=strlen(y);
for(i=0;i<=Ly;++i)
{r[i]=0;}
for(i=0;i<Lx;++i)
{
for(j=0;j<Ly;++j)
{
if(x[i]==y[j])
{s[j+1]=r[j]+1;}
else if(r[j+1]>=s[j]) {s[j+1]=r[j+1];}
else
{s[j+1]=s[j];}
}
for(j=1;j<=Ly;++j)
{r[j]=s[j];}
}
printf("%d\n",r[Ly]);
}
return
0;
}
原文:http://www.cnblogs.com/52Cyan/p/3674369.html