#include #include #include using namespace std; bool isForw(vector & a, string& w, int start) { for (int i = start; i & a, vector & b) { int ai = 0, bi = 0; while(true) { if (a[ai] == b[bi]) { cout << a[ai] << " "; ai++; bi++; } else { if (a[ai] < b[bi] && !isForw(b, a[ai], bi) ) { cout << a[ai++] << " "; } if (a[ai] < b[bi] && isForw(b, a[ai], bi) ) { cout << b[bi++] << " "; } if (a[ai] > b[bi] && !isForw(a, b[bi], ai) ) { cout << b[bi++] << " "; } if (a[ai] > b[bi] && isForw(a, b[bi], ai) ) { cout << a[ai++] << " "; } } if (ai == a.size()) { for (int i = bi; i< b.size(); i++) { cout << b[i] << " "; } break; } if (bi == b.size()) { for (int i = ai; i < a.size(); i++) { cout << a[i] << " "; } break; } } cout << "." << endl; } int main () { while (true) { //hlavni vector a; vector b; string tmp; cin >> tmp; if (tmp == ".") break; a.push_back(tmp); while (true) { // radek string tmp; cin >> tmp; if (tmp == ".") break; a.push_back(tmp); } while (true) { // radek string tmp; cin >> tmp; if (tmp == ".") break; b.push_back(tmp); } merge(a,b); } return 0; }