#include #include #include #include #include #include #include #include #include using namespace std; #define SIZE(s) int((s).size()) #define REP(i,n) for (int i=0; i<(n); i++) int best[2048][2048]; int da[2048][2048]; int db[2048][2048]; char A[2048][12]; char B[2048][12]; int cmp[2048][2048]; int main() { while (1) { int LA = 0; while (1) { scanf("%s ",A[LA++]); if (A[LA-1][0]=='.' && A[LA-1][1]==0) { LA--; break; } } if (LA==0) break; int LB = 0; while (1) { scanf("%s ",B[LB++]); if (B[LB-1][0]=='.' && B[LB-1][1]==0) { LB--; break; } } REP(i,LA) REP(j,LB) cmp[i][j]=strcmp(A[i],B[j]); REP(i,LA+1) best[i][0] = i; REP(i,LB+1) best[0][i] = i; for (int i=1; i<=LA; i++) for (int j=1; j<=LB; j++) { if (cmp[LA-i][LB-j]==0) { best[i][j] = 1 + best[i-1][j-1]; da[i][j] = db[i][j] = 1; } else { if (cmp[LA-i][LB-j]<0) { if (best[i-1][j] <= best[i][j-1]) { best[i][j] = best[i-1][j] + 1; da[i][j] = 1; db[i][j] = 0; } else { best[i][j] = best[i][j-1] + 1; da[i][j] = 0; db[i][j] = 1; } } else { if (best[i-1][j] < best[i][j-1]) { best[i][j] = best[i-1][j] + 1; da[i][j] = 1; db[i][j] = 0; } else { best[i][j] = best[i][j-1] + 1; da[i][j] = 0; db[i][j] = 1; } } } } int KA=LA, KB=LB; while (KA && KB) { if (da[KA][KB]) printf("%s ",A[LA-KA]); else printf("%s ",B[LB-KB]); int nKA = KA - da[KA][KB]; int nKB = KB - db[KA][KB]; KA = nKA; KB = nKB; } while (KA) { printf("%s ",A[LA-KA]); KA--; } while (KB) { printf("%s ",B[LB-KB]); KB--; } printf(".\n"); } }