http://acm.hdu.edu.cn/showproblem.php?pid=1159
View Code
1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 char str1[10000] ; 5 char str2[10000] ; 6 int c[10000][10000] ; 7 int main() 8 { 9 int len1, len2, i, j ; 10 while(cin>>str1>>str2) 11 { 12 len1 = strlen(str1) ; 13 len2 = strlen(str2) ; 14 for(i=0; i<len1; i++) 15 c[i][0] = 0 ; 16 for(j=0; j<len2; j++) 17 c[0][j] = 0 ; 18 for(i=1; i<len1+1; i++) 19 for(j=1; j<len2+1; j++) 20 { 21 if(str1[i-1]==str2[j-1]) 22 c[i][j] = c[i-1][j-1] + 1 ; 23 else c[i][j] = c[i][j-1]>c[i-1][j]?c[i][j-1]:c[i-1][j] ; 24 } 25 cout<<c[len1][len2]<<endl ; 26 } 27 return 0 ; 28 }