POJ1318 Word Amalgamation

来源:互联网 发布:沪港通个股数据查询 编辑:程序博客网 时间:2024/06/05 01:10

题目链接: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"== 0break;
        dict.insert(ch);
    }
    
while (true)
    {
        gets(ch);
        
if( strcmp(ch, "XXXXXX"== 0break;
        
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;
}