//先将所有的字符串进行一个排序,然后再通过一个个的排序之后的比较,这题就很简单了! #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; vector<string> vv; int main() { int size, i; string str, tmp; while (cin >> str) { if (str == "XXXXXX") break; vv.push_back(str); } sort(vv.begin(), vv.end()); bool flag; size = vv.size(); while (cin >> str) { if (str == "XXXXXX") break; sort(str.begin(), str.end()); flag = false; for (i = 0; i < size; i++) { tmp = vv[i]; sort(tmp.begin(), tmp.end()); if (tmp == str) { flag = true; cout << vv[i] << endl; } } if (flag) cout << "******" << endl; else cout << "NOT A VALID WORD" << endl << "******" << endl; } system("pause"); }