#include #include #include #define MAXS 5000 char w1[MAXS][16]; char w2[MAXS][16]; int w1c,w2c; int best[MAXS][MAXS]; int count[MAXS][MAXS]; int main() { int i,j,k; scanf("%s",w1[0]); while (w1[0][0]!='.') { w1c=1; while (w1[w1c-1][0]!='.') { scanf("%s",w1[w1c]); w1c++; } scanf("%s",w2[0]); w2c=1; while (w2[w2c-1][0]!='.') { scanf("%s",w2[w2c]); w2c++; } w1c--; w2c--; /* printf("%d %d\n",w1c,w2c); */ best[0][0]=-1; for (i=1; i<=w1c; i++) { best[i][0]=1; count[i][0]=i; } for (j=1; j<=w2c; j++) { best[0][j]=2; count[0][j]=j; for (i=1; i<=w1c; i++) { k=strcmp(w1[w1c-i],w2[w2c-j]); /* printf("%s %s %d\n",w1[w1c-i],w2[w2c-j],k); */ if (k==0) { best[i][j]=3; count[i][j]=count[i-1][j-1]+1; continue; } if (count[i-1][j]count[i][j-1]) { best[i][j]=2; count[i][j]=count[i][j-1]+1; continue; } if (k<0) { best[i][j]=1; count[i][j]=count[i-1][j]+1; continue; } best[i][j]=2; count[i][j]=count[i][j-1]+1; continue; } } i=w1c; j=w2c; while (best[i][j]!=-1) { /* printf("%d",best[i][j]); */ if (best[i][j]&1) { printf("%s ",w1[w1c-i]); if (best[i][j]==3) j--; i--; continue; } printf("%s ",w2[w2c-j]); j--; } printf(".\n"); scanf("%s",w1[0]); } return 0; }