题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1318
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
#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 << " NOTAVALIDWORD " << endl;
}
cout << " ****** " << endl;
}
return 0 ;
}
#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 << " NOTAVALIDWORD " << endl;
}
cout << " ****** " << endl;
}
return 0 ;
}