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

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

转载请注明出处:http://blog.csdn.net/u012860063天资

题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=1113

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
 

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

hdu1113 Word Amalgamation(详解--map和string的运用)的更多相关文章

  1. poi导出word表格详解 超详细了

    转:非常感谢原作者 poi导出word表格详解 2018年07月20日 10:41:33 Z丶royAl 阅读数:36138   一.效果如下 二.js代码 function export_word( ...

  2. 详解 Map集合

    (请关注 本人"集合总集篇"博文--<详解 集合框架>) 首先,本人来讲解下 Map集合 的特点: Map集合 的特点: 特点: 通过 键 映射到 值的对象 一个 映射 ...

  3. java如何对map进行排序详解(map集合的使用)

    今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单介绍Map 在讲解Map排 ...

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

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

  5. 详解Map集合体系及方法entrySet、keySet、values

    简单回顾Map集合: Map表示映射关系,以键值对的方式来保存数据.key和value一一对应.key是唯一的,不可重复,而value是可重复的,可以被多个key关联.虽然Map是放入两个数据,但是却 ...

  6. HDU1113 Word Amalgamation

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

  7. Java基础:String类详解,案例用户登录实现,案例手机号截取实现,案例敏感词替换实现;StringBuilder类详解,StringBuilder和String相互转换,附练习案例.

    1.API 1.1 API概述-帮助文档的使用 什么是API API (Application Programming Interface) :应用程序编程接口 java中的API 指的就是 JDK ...

  8. C++中的STL中map用法详解(转)

    原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解   Map是STL的一个关联容器,它提供 ...

  9. STL map 常见用法详解

    <算法笔记>学习笔记 map 常见用法详解 map翻译为映射,也是常用的STL容器 map可以将任何基本类型(包括STL容器)映射到任何基本类型(包括STL容器) 1. map 的定义 / ...

随机推荐

  1. WEB下渗透测试经验技巧(全)[转载]

    Nuclear’Atk 整理的: 上传漏洞拿shell: 1.直接上传asp.asa.jsp.cer.php.aspx.htr.cdx….之类的马,拿到shell.2.就是在上传时在后缀后面加空格或者 ...

  2. 1.Windows服务-->添加一个简单的服务

    Windows服务应用程序是一种需要长期运行的应用程序,它对于服务器环境特别适合.它没有用户界面,并且也不会产生任何可视输出.任何用户消息都会被 写进Windows事件日志.计算机启动时,服务会自动开 ...

  3. spring 学习总结(一)

    一.spring概述 1.spring 是什么? Spring是一个开放源代码的设计层面框架,他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用.Spring是于2 ...

  4. java导入excle表格,并且对表格进行相应的修改,并对表格数据进行整理,最后导出本地表格等一系列操作

    1.首先创建一个java项目 完成效果如下图所示 2.导入以下jar包 3.代码如下 其中行和列的操作是根据需求自动划分的 public class auto_date { private stati ...

  5. Effective C++ .13使用智能指针来引用资源

    #include <iostream> #include <cstdlib> #include <memory> using namespace std; clas ...

  6. phpmyadmin数据表结构没有显示注释列

    新开的一个项目,用phpmyadmin作为图形化操作数据库工具.创建数据表时为其每列添加好注释,浏览数据表内容有显示注释内容,但是查看数据表结构没有显示注释列,不方便直观查看数据表每列的意思. 上网搜 ...

  7. JavaScript This -笔记

    参考文章:blog.crimx.com/2016/05/12/understanding-this/ 在es6箭头函数之前this是执行时候确定的,而非定义时候确定.函数都是被调用的,调用时找前面调用 ...

  8. 关于输入框在谷歌浏览器 ie 浏览器中 黄色背景的去除

    谷歌有自己对input 的填充色 加上下面的css 就可以了 input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white ins ...

  9. C语言转置矩阵算法

    对一个nxn阶的矩阵进行转置,算法如下: #include <stdio.h> #define n 3 void MM(int a[][n]) { int i,j,temp; ;i < ...

  10. 浅谈用于WEBGIS开发最重要的4个HTML5特性

    WebGIS是GIS与Internet相结合的产物,一般Internet的开发手段都可用于WEBGIS的开发,比较流行的有Javascript.FLash,到现在应该说市面上的WEBGIS产品和具有的 ...