#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]; int main() { while (1) { vector A, B; string line, word; getline(cin,line); if (line == ".") break; stringstream SS(line); while (SS >> word) A.push_back(word); A.pop_back(); getline(cin,line); stringstream SS2(line); while (SS2 >> word) B.push_back(word); B.pop_back(); int LA = SIZE(A), LB = SIZE(B); 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 (A[LA-i] == B[LB-j]) { best[i][j] = 1 + best[i-1][j-1]; da[i][j] = db[i][j] = 1; } else { if (A[LA-i] < B[LB-j]) { 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; vector res; while (KA && KB) { if (da[KA][KB]) res.push_back(A[LA-KA]); else res.push_back(B[LB-KB]); int nKA = KA - da[KA][KB]; int nKB = KB - db[KA][KB]; KA = nKA; KB = nKB; } while (KA) { res.push_back(A[LA-KA]); KA--; } while (KB) { res.push_back(B[LB-KB]); KB--; } REP(i,SIZE(res)) cout << res[i] << " "; cout << "." << endl; } }