#include #include #include #define MAXW 2100 #define MAXLEN 1000 typedef struct Words { char *w; int sentence; int pos; } Words; /* Vstupní texty */ char word[2][MAXW+2][MAXLEN+2]; int n,n0,n1; Words w[2*MAXW+2]; int numseq[2][MAXW+2], diffwcnt; /* 0 == slovo společné oběma sekvencím, 1 == použijeme originální vzpomínku, 2 == použijeme novou vzpomínku */ int best[MAXW+2][MAXW+2]; int bestlen[MAXW+2][MAXW+2]; int bestbeg[MAXW+2][MAXW+2]; int main(void) { int i,j,tmp; /* Načteme originální vzpomínky */ for(i=0;; i++) { scanf(" %s ", word[0][i]); if(word[0][i][0]=='.') break; w[i].w = word[0][i]; w[i].sentence = 0; w[i].pos = i; } n0 = i; if(n0==0) return 0; /* Načteme vkládané vzpomínky */ for(i=0;; i++) { scanf(" %s ", word[1][i]); if(word[1][i][0]=='.') break; w[n0+i].w = word[1][i]; w[n0+i].sentence = 1; w[n0+i].pos = i; } n1 = i; n=n0+n1; diffwcnt=0; for(i=0;i0 && strcmp(w[i].w, w[i-1].w)) diffwcnt++; numseq[w[i].sentence][w[i].pos] = diffwcnt; } for(i=0;i=0;i--) for(j=n1-1;j>=0;j--) { if(numseq[0][i]==numseq[1][j]) { bestlen[i][j] = 1+bestlen[i+1][j+1]; bestbeg[i][j] = numseq[0][i]; best[i][j] = 0; continue; } if(bestlen[i+1][j] < bestlen[i][j+1] || (bestlen[i+1][j] == bestlen[i][j+1] && numseq[0][i] < numseq[1][j])) { bestlen[i][j] = bestlen[i+1][j]+1; bestbeg[i][j] = numseq[0][i]; best[i][j] = 1; } else { bestlen[i][j] = bestlen[i][j+1]+1; bestbeg[i][j] = numseq[1][j]; best[i][j] = 2; } } i=0; j=0; while(1) { tmp = best[i][j]; if(tmp==0 || tmp==1) printf("%s ", word[0][i]); if(tmp==2) printf("%s ", word[1][j]); if(tmp==-1) break; if(tmp==0 || tmp==2) j++; if(tmp==0 || tmp==1) i++; } printf(".\n"); return 0; }