POJ1318 Word Amalgamation
题目链接: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;
}
#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;
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2009-09-12 16:42 Phinecos(洞庭散人) 阅读(886) 评论(0) 编辑 收藏 举报