Word Amalgamation

链接

[https://vjudge.net/contest/212939#problem/C]

题意

给你个字典,字典包含若干个单词;
再给你若干个单词,让你输出跟这个单词有相同的字母的字典里的单词(不考虑顺序)

分析

STL set的应用以及next_permutation的应用
用set保存字典里的单词,对于每个要查的单词s先按字典序排列,然后next_permutation生成s的全排列
再用set.find(s)找是否存在这种排列,有输出。没有输出“no”;

代码

#include<iostream>
#include<set>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    set<string> se;
    set<string>::iterator it;
    string s;
    int cnt=0;
    //freopen("in.txt","r",stdin);
    while(cin>>s){
        if(s=="XXXXXX") {
            cnt++;
            continue;
        }
        if(cnt==0)
        se.insert(s);
        if(cnt==2) break;
        if(cnt==1){
            bool flag=0;
            sort(s.begin(),s.end());
            do{
                it=se.find(s);
                if(it!=se.end()){
                    cout<<s<<endl;
                    flag=1;
                }
            }while(next_permutation(s.begin(),s.end()));
            if(!flag) cout<<"NOT A VALID WORD\n";
            cout<<"******\n";
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/mch5201314/p/9873330.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值