首页 > 代码库 > hdu 1113 Word Amalgamation (map)

hdu 1113 Word Amalgamation (map)

# include <stdio.h>
# include <string>
# include <map>
# include <iostream>
# include <algorithm>
using namespace std;
int main()
{
	string s,t;
	int flag;
	map<string,string>q;
	while(cin>>s&&s!="XXXXXX")
	{
		t=s;
		sort(s.begin(),s.end());
		q[t]=s;
	}
	while(cin>>s&&s!="XXXXXX")
	{
		sort(s.begin(),s.end());
		map<string,string>::iterator it;
		flag=0;
		for(it=q.begin();it!=q.end();it++)
		{
			if(it->second==s)
			{
				cout<<it->first<<endl;
				flag=1;
			}
		}
		if(!flag)
			cout<<"NOT A VALID WORD"<<endl;
		cout<<"******"<<endl;
	}
	return 0;
}