#include <stdio.h>
#include <string.h>
#define N 500
void LCS( char x[], char y[],int c[][N])
{
int i, j;
for(i = 1; i <= strlen(x); i++)
c[i][0] = 0;
for(i = 0; i <= strlen(y); i++)
c[0][i] = 0;
for(i = 1; i <= strlen(x); i++)
for(j = 1; j<=strlen(y); j++)
{
if(x[i-1]==y[j-1])
c[i][j] = c[i-1][j-1] + 1;
else if(c[i-1][j]>=c[i][j-1])
c[i][j] = c[i-1][j];
else
c[i][j] = c[i][j-1];
}
}
int main()
{
char x[N];
char y[N];
int c[N][N];
while(scanf("%s %s", x, y) !=EOF)
{
int lx=strlen(x);
int ly=strlen(y);
LCS(x, y, c);
printf("%d\n", c[lx][ly]);
}
return 0;
}
common sequence
最新推荐文章于 2022-02-14 03:51:28 发布