//Stephen Siena //CSE 40872 - Problem 8 //September 18, 2009 #include #include #include using namespace std; void findCommonString(string str1, string str2); int main(){ string word1; string word2; while(true){ cin >> word1; if (cin.eof()) break; cin >> word2; findCommonString(word1, word2); } return 0; } void findCommonString(string str1, string str2){ sort(str1.begin(), str1.end()); sort(str2.begin(), str2.end()); string commonPerm; string::iterator it1 = str1.begin(); string::iterator it2 = str2.begin(); while(it1 != str1.end() && it2 != str2.end()){ if (*it1 > *it2) it2++; else if (*it1 < *it2) it1++; else{ commonPerm += *it1; it1++; it2++; } } cout << commonPerm << endl; }