//最长公共子序列 #include<stdio.h> #include<string.h> #define MAX_LEN 1000 char sz1[MAX_LEN]; char sz2[MAX_LEN]; int aMaxLen[MAX_LEN][MAX_LEN]; int main() { scanf("%s%s",sz1,sz2); while(sz1[0]!='@'){ int nLength1=strlen(sz1); int nLength2=strlen(sz2); //int nTmp; int i,j; for(i=0;i<=nLength1;i++) aMaxLen[i][0]=0; for(j=0;j<=nLength2;j++) aMaxLen[0][j]=0; for(i=0;i<nLength1;i++){ for(j=0;j<nLength2;j++){ if(sz1[i]==sz2[j]) aMaxLen[i][j]=aMaxLen[i-1][j-1]+1; else{ int nLen1=aMaxLen[i][j-1]; int nLen2=aMaxLen[i-1][j]; if(nLen1>nLen2) aMaxLen[i][j]=nLen1; else aMaxLen[i][j]=nLen2; } } } printf("%d ",aMaxLen[nLength1-1][nLength2-1]); scanf("%s%s",sz1,sz2); } return 0; }