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. jni.h头文件详解一

    1.jni.h头文件路径: /usr/lib/jvm/jdk_1.6.0_43/include/jni.h 2.jni.h头文件组成分析图: 3.下面通过上图进行分析讲解jni.h头文件. 一. jn ...

  2. XUTils框架的学习(三)

    前面两章说了xutils框架的引入和注解模块的使用和数据库模块的使用,想了解的朋友可以去看看. 前面在说数据库模块的操作的时候是手动创建数据库并保存在asset文件夹里面,再通过I/O将数据库写进应用 ...

  3. HDU-1339 A Simple Task

    http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...

  4. windwos server 2008下iis7各种操作

    1.发布一个asp程序带access数据库的 默认server 08是安装了iis7的,但是它默认没支持asp这项,这时你可以直接去控制面板--程序和功能--打开或关闭windows功能(双击打开)- ...

  5. 曾经记录——asp.net中的点滴

    “<%#....%>”这是数据绑定,里面可以调用C#的方法,比如在数据控件里执行绑定某个字段<%# Eval("Name")%>这样帮顶一个Name的字段. ...

  6. 根据地址查询经纬度.html

    <html xmlns="http://www.w3.org/1999/xhtml"><head> <title>根据地址查询经纬度</t ...

  7. GPU 的硬件基本概念,Cuda和Opencl名词关系对应

    GPU 的硬件基本概念 Nvidia的版本: 实际上在 nVidia 的 GPU 里,最基本的处理单元是所谓的 SP(Streaming Processor),而一颗 nVidia 的 GPU 里,会 ...

  8. Lottery - CodeForces 589I(水)

    题目大意:有N个球K个人,现在要给这N个球涂上K种颜色,要求使抽到球的不同颜色的概率一致(N确保是K的倍数),求出来至少要给多少个球重新涂上颜色. 分析:先求出来所有球的每种颜色的个数,然后不到平均数 ...

  9. QT_校园导航(绘制路线已实现)_Updata_详细注释

    //MainWidget.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include " ...

  10. java+springboot+bootstrap-fileInput 文件上传前后台完整示例

    先看效果图