标签:name har std strlen lease first color char def
#include<bits/stdc++.h> #define N 100 using namespace std; void output_array(int a[][N],int m,int n) { for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) printf("%d%c",a[i][j],(j == n-1 ? ‘\n‘:‘ ‘)); } } int main() { int c[N][N]; int t; scanf("%d",&t); while(t--) { char str_1[N], str_2[N],lcs[N]; printf("please enter the first string:\n"); scanf("%s",str_1+1); printf("please enter the second string:\n"); scanf("%s",str_2+1); memset(c,0,sizeof(c)); int len_1 = strlen(str_1+1); int len_2 = strlen(str_2+1); for(int i = 1; i <= len_1; i++ ) { for(int j = 1; j <= len_2; j++) { if(str_1[i] == str_2[j]) { c[i][j] = c[i-1][j-1]+1; lcs[c[i][j]-1] = str_1[i]; } else if(c[i][j-1] >= c[i-1][j]) c[i][j] = c[i][j-1]; else c[i][j] = c[i-1][j]; } } printf("len_1:%d\tlen_2:%d\n",len_1, len_2); output_array(c,len_1+1, len_2+1); putchar(‘\n‘); printf("LCS is \"%s\"\n\n",lcs); } return 0; }
标签:name har std strlen lease first color char def
原文地址:https://www.cnblogs.com/zhang-zsq/p/12844960.html