Word Amalgamation

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 words. Your task is to write a program that can unscramble words. 
 
Input
The input contains four parts:

1. a dictionary, which consists of at least one and at most 100 words, one per line; 
2. a line containing XXXXXX, which signals the end of the dictionary; 
3. one or more scrambled `words' that you must unscramble, each on a line by itself; and 
4. another line containing XXXXXX, which signals the end of the file.

All words, including both dictionary words and scrambled words, consist only of lowercase English letters and will be at least one and at most six characters long. (Note that the sentinel XXXXXX contains uppercase X's.) The dictionary is not necessarily in sorted order, but each word in the dictionary is unique.

 
Output
For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. Each word in this list must appear on a line by itself. If the list is empty (because no dictionary words can be formed), output the line ``NOT A VALID WORD" instead. In either case, output a line containing six asterisks to signal the end of the list.
 
 
Sample Input
tarp
given
score
refund
only
trap
work
earn
course
pepper
part
XXXXXX
resco
nfudre
aptr
sett
oresuc
XXXXXX
 
Sample Output
score
******
refund
******
part
tarp
trap
******
NOT A VALID WORD
******
course
******
 
分析:题意是给你一个单词字典,每次询问一串字符,问能否组成字典里的单词,并按字典序输出。这题开始尝试暴力查找,但没注意到要按字典序,后来尝试用set,但第三个样例出错了,怎么也想不通,最后换成map,把字典里的每个单词里的字符排序并与原单词对应,然后查找时排个序再比较就很方便了。
最后说一句,map大法好~~~
 
 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
#define INF -100000
typedef long long ll;
const int maxn=;
string words,tmp,query;
map<string,string> ans;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(cin>>words){
if(words=="XXXXXX") break;
tmp=words;
sort(words.begin(),words.end());
ans[tmp]=words;
}
while(cin>>query){
if(query=="XXXXXX") break;
int flag=;
sort(query.begin(),query.end());
for(map<string,string>::iterator it=ans.begin();it!=ans.end();it++)
if(it->second==query){
cout<<it->first<<endl;
flag=;
}
if(!flag) printf("NOT A VALID WORD\n");
printf("******\n");
}
return ;
}

HDU-1113(map的运用)的更多相关文章

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...

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

    Problem Description In millions of newspapers across the United States there is a word game called J ...

  3. hdu 1113 Word Amalgamation

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...

  4. hdu - 1113 Word Amalgamation (stl)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典 ...

  5. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

  6. hdu 1075 (map)

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...

  7. hdu 1247 map的使用

    http://acm.hdu.edu.cn/showproblem.php?pid=1247 Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    ...

  8. hdu 4941 map的使用

    http://acm.hdu.edu.cn/showproblem.php?pid=4941 给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是: 1 ...

  9. hdu 2112 HDU Today(map与dijkstra的结合使用)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. HDU 5167(map + 暴力)

    题意:给出一个数n,问n能否是斐波那契数列中数的乘积 先刷选 斐波那契数列,然后就枚举 #include <cstdio> #include <cstring> #includ ...

随机推荐

  1. leetcode面试准备: CountPrimes

    1 题目 Description: Count the number of prime numbers less than a non-negative number, n. 接口:public in ...

  2. python-urllib2模块

    参考: http://blog.csdn.net/wklken/article/details/7364390 http://hankjin.blog.163.com/blog/static/3373 ...

  3. Oracle core02_数据块

    数据更改 oracle core完成了oracle的核心功能,recovery,读一致性等. 深入的了解oracle的机制,就从一个最简单的更新开始.对于oracle来说,最大的一个特性就是写了两次数 ...

  4. Datetime中yyyy-MM-dd-hh-mm-ss的格式

    namespace yyyy_MM_dd_hh_mm{    class Program    {        static void Main(string[] args)        { wh ...

  5. (转载)可重入函数(reentrant function)

    (转载)http://blog.163.com/xu_jin_rong/blog/static/1491966220086775017178 由于cublog系统的缘故,将前段时间写的一篇blog文章 ...

  6. android获取package name

    下载apk resigner(此被,,) 另外一个下载url 配置好android 环境,ANDROID_HOME 和路径直接到sdk,将.apk拖到此apk resigner,将会得出package ...

  7. HDU 4737 A Bit Fun 2013成都 网络赛 1010

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题目大意:给定一系列数,F(i,j)表示对从ai到aj连续求或运算,(i<=j)求F(i, ...

  8. poj 1995 Raising Modulo Numbers【快速幂】

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5477   Accepted: ...

  9. jmeter控制器

    1.仅一次控制器  这个控制器可以保证线程在多次循环跑得情况下只登陆一次 2.循环控制器(Loop Controller:设置循环次数 结果: 3. ForEach控制器(ForEach Contro ...

  10. CentOS 7下安装xampp和testlink

    记录一下最近安装testlink的经历,供大伙儿参考,有问题可以留言讨论,这里就不截图了 先说下安装版本: CentOS-7.0-1406-x86_64-DVDxampp-linux-1.8.3-5- ...