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;
}

hdu 1113 Word Amalgamation (map)

时间: 2024-10-24 21:34:56

hdu 1113 Word Amalgamation (map)的相关文章

HDU 1113 Word Amalgamation (map 容器 + string容器)

http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in th

HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)

Problem Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four wor

hdu - 1113 Word Amalgamation (stl)

http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典序输出字典中的原字符串. 我开始是直接用了 sort, 用一个结构体记录了所有字符串,和相应下标,输出的时候在用了冒泡排序. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include &l

hdu1113 Word Amalgamation(超详细解释--map和string的运用)

转载请注明出处:http://blog.csdn.net/u012860063天资 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 来吧!!欢迎"热爱编程"的同学报考杭电,期待你加入"杭电ACM集训队"! 7月22-8月21多校联合训练期间,会根据实际负载关闭部分模块,若有不便,请谅解~ Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Me

HDU1113 Word Amalgamation

问题链接:HDU1113 Word Amalgamation. 这个问题是一个字典问题,自然用map来实现.问题在于还需要转个弯,不然会掉进陷阱里去的. 查字典问题,通常是单词按照字典顺序存放,然后将要查的单词拆成字母,按单词的字母顺序去查字典.然而要是这样做程序的逻辑就太零碎繁杂了. 于是,把单词中的字符排个顺序作为关键字,来查单词的话就方便了.需要注意的一点,不同的单词有可能具有相同的关键字. 这个程序的关键有容器类map的使用,算法库<algorithm>中函数sort()的使用. AC

poj 1318 Word Amalgamation

Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but

hdu 1251 统计难题 (map水过)

# include <stdio.h> # include <algorithm> # include <string.h> # include <map> # include <iostream> using namespace std; int main() { char a; string x; map<string,int>q; while(true) { scanf("%c",&a); if(a=

hdu 4941 Magical Forest(Map)

http://acm.hdu.edu.cn/showproblem.php?pid=4941 因为地图的行和列很大,操作次数也很多,直接循环模拟肯定不行.但可以用map映射一下,当交换行和列的时候,直接交换它们的映射值,直接O(1)进行交换. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <list> #include <stack

Uva 642 - Word Amalgamation sort qsort

 Word Amalgamation  In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four wor