#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
char c1[1001],c2[1001];
int dp[1011][1011];
void read(){
// ifstream cin("in.txt");
int i,j,k;
int n1,n2;
while(cin>>c1>>c2)
{
n1=strlen(c1);
n2=strlen(c2);
for(i=1;i<=n1;i++)
for(j=1;j<=n2;j++)
{
if(c1[i-1]==c2[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
cout<<dp[n1][n2]<<endl;
}
}
int main(){
read();
return 0;
}
转载于:https://www.cnblogs.com/zhaozhe/archive/2011/07/09/2101797.html