//---------------MY CODE------------------------- #include<iostream> #include<vector> #include<string> using namespace std; string get(string word) { for(int i = 1; i != word.size(); ++i) { char key = word[i]; for(int j = i-1; j >= 0 && word[j] > key; --j) //升序 word[j+1] = word[j]; word[j+1] = key; } return word; } void marry(const vector<string> &dictionary, const string &word) { vector<string>::size_type i = 0; bool flag = false; for(; i != dictionary.size(); ++i) { if(get(word) == get(dictionary[i]) && word != dictionary[i]) { if(flag == true) cout << " "; cout << dictionary[i]; flag = true; } } if(flag == false) cout << ":("; cout << endl; } int main() { vector<string> dictionary; cout << "Fill in the dictinory:" << endl; string word; while(cin >> word && word != "******") dictionary.push_back(word); cout << "Enter some words(Ctr+Z to end):" << endl; while(cin >> word) { marry(dictionary, word); } return 0; }
例子:
tarp given score refund only trap work earn course pepper part ****** resco nfudre aptr sett oresuc
输出;