提交时间:2023-11-25 11:25:50
运行 ID: 112281
#include <stdio.h> #include <stdlib.h> #include <string.h> int *pln1 , *pln2; char a[10010] , b[10010]; int main() { int i , j , lena , lenb ; gets(a); gets(b); lena = strlen(a); lenb = strlen(b); pln1 = (int*)calloc( lenb + 1 , sizeof(int) ); memset( pln1 , 0 , sizeof(pln1) ); pln2 = (int*)calloc( lenb + 1 , sizeof(int) ); memset( pln2 , 0 , sizeof(pln2) ); for( i = 1 ; i <= lena ; i++ ) { for( j = 1 ; j <= lenb ; j++ ) { if( a[i-1] == b[j-1] ) { pln2[j] = pln1[j-1] + 1; } else if( pln1[j] >= pln2[j-1] ) { pln2[j] = pln1[j]; } else { pln2[j] = pln2[j-1]; } } free(pln1); pln1 = pln2; pln2 = (int*)calloc( lenb + 1 , sizeof(int) ); memset( pln2 , 0 , sizeof(pln2) ); } printf( "%d\n" , pln1[lenb] ); return 0; }