POJ1318 Word Amalgamation

PKU ACM 1318题解
本文提供了一段解决PKU ACM 1318问题的C++代码,该代码使用了标准模板库(set)来实现字典功能,并通过全排列算法找出所有可能的单词组合,最后对比字典进行匹配。

题目链接: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 ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值