题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1318
复制代码
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
set<string> dict;
string word;
char ch[10];
while (true)
{
gets(ch);
if( strcmp(ch, "XXXXXX") == 0) break;
dict.insert(ch);
}
while (true)
{
gets(ch);
if( strcmp(ch, "XXXXXX") == 0) break;
int count=0;
word = ch;
sort( word.begin(), word.end());
do
{
if( dict.find(word) != dict.end() )
{
cout << word.c_str() <<endl;
count++;
}
}while( next_permutation( word.begin(), word.end() ));
if( count == 0)
{
cout << "NOT A VALID WORD" << endl;
}
cout << "******" << endl;
}
return 0;
}
复制代码
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2009/09/12/1565374.html,如需转载请自行联系原作者