#include #include #include #include using namespace std; int main() { map m; string words1[20010], words2[20010]; char w[15]; int i, j, r1, r2, p1, p2, d1, d2, zhoda; while (1) { m.clear(); scanf("%s", w); if (strcmp(w, ".") == 0) break; else { words1[0] = string(w); i = 0; while (words1[i++][0] != '.' || i == 0) { scanf("%s", w); words1[i] = string(w); } d1 = i; i = 0; do { scanf("%s", w); words2[i] = string(w); m[words2[i]] = i; } while (words2[i++][0] != '.'); d2 = i; /*for (i = 0; i < d1; i++) printf("%s;", words1[i].c_str()); printf("\n"); for (i = 0; i < d2; i++) printf("%s;", words2[i].c_str()); */ p1 = p2 = -1; r1 = r2 = -1; do { p1++; p2++; zhoda = 0; for (r1++; r1 < d1 && !zhoda; r1++) { zhoda = 0; if (m.count(words1[r1]) > 0) { zhoda = 1; r2 = m[words1[r1]]; } } r1--; //printf("nasiel som zhodu na %d a %d\n", r1, r2); zhoda = 0; while (p1 != r1 || p2 != r2) { zhoda = 1; if (p1 == r1) strcpy(w, words2[p2++].c_str()); else if (p2 == r2) strcpy(w, words1[p1++].c_str()); else strcpy(w, words1[p1].compare(words2[p2]) < 0 ? words1[p1++].c_str() : words2[p2++].c_str()); if (w[0] == '.') printf("."); else printf("%s ", w); } //if (!zhoda) { if (words1[p1][0] == '.') printf("."); else printf("%s ", words1[p1].c_str()); } } while (words1[p1][0] != '.' || words2[p2][0] != '.'); printf("\n"); } } return 0; }