回复 36楼 kingsroot
提示: 作者被禁止或删除 内容自动屏蔽
#include <stdio.h> #include <string.h> int main(void) { char *a = "adbccadebbca", *b = "edabccadece"; int i, j; int len_a = strlen(a), len_b = strlen(b); int dp[2][101] = {}; int max_begin, max_len = 0; for (i = 1; i <= len_a; ++i) for (j = 1; j <= len_b; ++j) { int i_idx = i%2; if (a[i-1] == b[j-1]) { dp[i_idx][j] = dp[(i-1)%2][j-1] + 1; if (dp[i_idx][j] > max_len) { max_begin = i - dp[i_idx][j]; max_len = dp[i_idx][j]; } } else dp[i_idx][j] = 0; } printf("%.*s\n", max_len, a + max_begin); return 0; }