版权声明:本文为博主原创文章。未经博主同意不得转载。

vasttian https://blog.csdn.net/u012860063/article/details/35338617

转载请注明出处: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)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2496    Accepted Submission(s): 1198

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 ******
Source
Mid-Central USA 1998
Recommend
Eddy

题意:先给你一些单词作为字典,在给一系列的单词查找字典中是否有这些单词(注意查找的单词,一个单词中的字母顺序是能够变得,也就是说单词之间仅仅要字母是一样的不用考虑顺序是否一样都要输出);

思路:用map和string便非常easy解决,先把字典存入map里,在逐一查找就OK。当然查找的时候须要一点小小的操作,详见代码解释;

map的具体使用方法:http://blog.csdn.net/u012860063/article/details/24435211

代码例如以下:

#include <cstdio>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{map<string,string>m;//定义map的变量和值都为string类型 string t, s;while(cin >> s){if( s == "XXXXXX") {    //注:string类型的是能够直接在字符串之间用"="或"=="进行赋值或推断的break;}t = s;sort(s.begin(),s.end());//直接对string类型的字符串用begin()和end()进行排序 m[t] = s;}while(cin >> s){if( s == "XXXXXX"){break;}int flag = 0;//用于记录字典里是否有要查询的单词 sort(s.begin(),s.end());//直接对string类型的字符串用begin()和end()进行排序 map<string,string>::iterator it;for(it = m.begin(); it != m.end(); it++){if(it->second == s)//it->second 为值,也就是map里第二个string的值 {cout<<it->first<<endl;//it->first 为索引键值,也就是map里第一个string的值 flag = 1;}}if(flag == 0)cout << "NOT A VALID WORD"<<endl; //和以下凝视掉的等效 cout << "******"<<endl;//   cout << "NOT A VALID WORD\n"<<; //    cout << "******\n"<<;}return 0;
}

转载于:https://www.cnblogs.com/mqxnongmin/p/10592653.html

hdu1113 Word Amalgamation(详解--map和string的运用)相关推荐

  1. java object数组转实体类_详解Java中String JSONObject JSONArray List实体类转换

    JSON使用阿里的fastJson为依赖包 gradle依赖管理如下: compile group: "com.alibaba", name: "fastjson&quo ...

  2. html 仿word页面,HTML+CSS入门 HTML页面仿WORD样式详解

    本篇教程介绍了HTML+CSS入门 HTML页面仿WORD样式详解,希望阅读本篇文章以后大家有所收获,帮助大家HTML+CSS入门. < 要求不再浏览器中添加office插件的前提下.展示WOR ...

  3. Java源码详解四:String源码分析--openjdk java 11源码

    文章目录 注释 类的继承 数据的存储 构造函数 charAt函数 equals函数 hashCode函数 indexOf函数 intern函数 本系列是Java详解,专栏地址:Java源码分析 Str ...

  4. Java中Map的entrySet()详解 || Map.Entry的详解

    Map中存放的元素均为键值对,故每一个键值对必然存在一个映射关系. Map中采用Entry内部类来表示一个映射项,映射项包含Key和Value Map.Entry的详解

  5. java string设置编码_详解Java中String类型与默认字符编码

    为什么写这个 至于为什么要写这个,主要是一句mmp一定要讲,绕了一上午,晕死 Java程序中的中文乱码问题一直是一个困扰程序员的难题,自己也不例外,早在做项目时就遇到过很多编码方式的坑,当时想填来着, ...

  6. 7-49 打印学生选课清单 (25 分)(思路+详解+map做法(一对多)+超时解决)Come baby!

    一:题目 假设全校有最多40000名学生和最多2500门课程.现给出每门课的选课学生名单,要求输出每个前来查询的学生的选课清单. 输入格式: 输入的第一行是两个正整数:N(≤40000),为前来查询课 ...

  7. 7-47 打印选课学生名单 (25 分)(两种做法)(思路加详解+map+vector做法+最后一个点超时解决)+兄弟们冲丫丫

    一:题目 假设全校有最多40000名学生和最多2500门课程.现给出每个学生的选课清单,要求输出每门课的选课学生名单. 输入格式: 输入的第一行是两个正整数:N(≤40000),为全校学生总数:K(≤ ...

  8. java 实现敏感词(sensitive word)工具详解使用说明

    sensitive-word 平时工作中,只要涉及到用户可以自由发言(博客.文档.论坛),就要考虑内容的敏感性处理. sensitive-word 基于 DFA 算法实现的高性能敏感词工具.工具使用 ...

  9. 7-48 银行排队问题之单窗口“夹塞”版 (30 分)(思路和详解+map做法)来呀Baby!

    一:题目 排队"夹塞"是引起大家强烈不满的行为,但是这种现象时常存在.在银行的单窗口排队问题中,假设银行只有1个窗口提供服务,所有顾客按到达时间排成一条长龙.当窗口空闲时,下一位顾 ...

最新文章

  1. 配置SQL Server 2008 镜像
  2. linux 关闭网络防火墙设置方法,CentOS Linux防火墙配置及关闭方法
  3. MySQL带DISTINCT关键字的查询
  4. java integer 包_java之学习基本类型包装类的概述及Integer类的概述和构造方法
  5. Halcon学习笔记:1D Measuring一维测量_fuse.hdev灯丝测量示例
  6. 物联网火爆,入门却太难了!
  7. linux编译寻找包含的头文件,Linux编写内核模块编译时找不到头文件
  8. MHA manage节点安装报错解决
  9. html按钮绑定点击事件无效,jquery添加的html元素按钮为何不执行类样式绑定的click事件...
  10. Android屏幕适配的两种方式
  11. python-gui-pyqt5的使用方法-7--partial 传递参数的方法:
  12. java调用win32_java调用win32api操作windows窗口
  13. 大漠插件最新版7.2107
  14. 对抗机器学习——Min Max模型(Towards Deep Learning Models Resistant to Adversarial Attacks)
  15. DB2操作指南及命令大全
  16. html 操作cookie,HtmlUnit 模拟浏览器以及Cookie使用示例
  17. 五线谱音名和组别对照表_五线谱最全知识及符号!
  18. 一小时快速建立数据分析平台
  19. 小组取什么名字好_最好的小组该取什么名字呢?
  20. 昔我往矣,杨柳依依,今我来思,雨雪霏霏

热门文章

  1. 本地提交spark_spark快速入门(三)-------spark部署及运行模式
  2. java 判断是否为cst格式_Java判断文件编码格式
  3. Educational Codeforces Round 50: F. Relatively Prime Powers(莫比乌斯函数)
  4. bzoj 4952: [Wf2017]Need for Speed(二分)
  5. 人脸检测caffe下步骤
  6. opencv 绘制图像直方图,实现直方图均衡化
  7. 图像读取、显示和保存
  8. [Python] 将两个列表合并为字典
  9. Git使用-.gitignore文件(使一些文件不上传到git)
  10. python机器学习案例系列教程——k均值聚类、k中心点聚类