#include #include using namespace std; void porovnej(void); string a,b; int main() { getline(cin,a); while(a!="."){ getline(cin,b); porovnej(); cout << endl; getline(cin,a); } return 0; } string nacti(string s) { string w = ""; while(s[0] == ' ') s=s.substr(1); while(s[0] != ' '){ w += s[0]; //cout << "fncout "<< s; s=s.substr(1); } while(w[0] == ' ') w=w.substr(1); //cout << "\n\n" << "nacteno: -" << w << "-\nze stringu -" << s << "-\n\n"; return w; } void porovnej() { string w1,w2; bool stop; string::size_type loc; while(a!="." && b!="." && a!=" ." && b!=" ."){ //cout << endl; //cout << endl; //cout << "a -" << a << endl; //cout << "b -" << b << endl; //cout << endl; w2=""; w1=""; stop = false; //nacteni prvniho slova w1=nacti(a); //cout << "py "; a = a.substr(w1.length()+1); //nacteni druheho slova w2=nacti(b); //cout << "ty "; b = b.substr(w2.length()+1); //pokud je prvni slovo mensi nez druhe navesti: if(w1.compare(w2)==-1) { //zjisteni jestli se prvni slovo nevyskytuje v druhe vete. loc = b.find(" " + w1 + " ", 0 ); if( loc != string::npos ) { //cout << "prvni "; cout << w2 << " " << b.substr(0, loc) << " " << w1 << " "; //cout << "druhy "; b=b.substr(loc+w1.length()+1); continue; } cout << w1 << " "; while(w1.compare(w2)==-1) { if(a=="." || stop) break; w1=nacti(a); //cout << "treti "; a = a.substr(w1.length()+1); if(w1.compare(w2)==0) break; if(w1.compare(w2)==1) { goto navesti; } b=" " + b; loc = b.find(" " + w1 +" ", 0 ); while(b[0] == ' ') b=b.substr(1); if( loc != string::npos ) { //cout << "ctvrty "; cout << w2 << " " << b.substr(0, loc) << "" << w1 << " "; //cout << "paty "; b=b.substr(loc+w1.length()+1); stop = true; continue; } cout << w1 << " "; } if(stop) continue; cout << w2 << " "; } //pokud je prvni slovo vetsi nez druhe else if(w1.compare(w2)==1) { //zjisteni jestli se prvni slovo nevyskytuje v druhe vete. loc = a.find(" " + w2 + " ", 0 ); if( loc != string::npos ) { //cout << "prvni "; cout << w1 << " " << a.substr(0, loc) << " " << w2 << " "; //cout << "druhy "; a=a.substr(loc+w2.length()+1); continue; } cout << w2 << " "; while(w1.compare(w2)==1) { if(b=="." || stop) break; w2=nacti(b); //cout << "\ntreti \n"; b = b.substr(w2.length()+1); if(w1.compare(w2)==0) break; if(w1.compare(w2)==-1) { goto navesti; } a = " " + a ; loc = a.find(" " + w2 + " ", 0 ); //cout << "\n" << loc << "\n"; while(a[0] == ' ') a=a.substr(1); if( loc != string::npos ) { //cout << "\nctvrty \n"; cout << w1 << " " << a.substr(0, loc) << "" << w2 << " "; //cout << "paty "; a=a.substr(loc+w2.length()+1); stop = true; continue; } cout << w2 << " "; } if(stop) continue; cout << w1 << " "; } //slova se rovnaji else { cout << w1 << " "; } } if(a=="." || a==" .") cout << b; else cout << a; }