传送门:Word Amalgamation
这个题目只要会熟练使用STL中的map就好了
AC代码
#include<cstdio>
#include<map>
#include<algorithm>
#include<iostream>
using namespace std;
map<string,string>m;
int main()
{
string dic,str,tmp;
int sum = 0;
while(cin>>dic)
{
if(dic == "XXXXXX") break;
tmp = dic;
sort(tmp.begin(),tmp.end());
m[dic] = tmp;
}
while(cin>>str)
{
if(str == "XXXXXX")break;
bool flag = false;
sort(str.begin(),str.end());
for(map<string ,string >::iterator it=m.begin();it!=m.end();it++)
{
if(it->second == str)
cout<<it->first<<endl,flag = true;
}
if(!flag)
cout << "NOT A VALID WORD"<<endl;
cout << "******"<<endl;
}
return 0;
}