//---------------MY CODE-------------------------#include#include #include 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 &dictionary, const string &word){ vector ::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 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
输出;
posted on 2012-11-13 22:55 阅读( ...) 评论( ...)