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 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
******
题意:先给你一些单词作为字典,在给一系列的单词查找字典中是否有这些单词(注意查找的单词,一个单词中的字母顺序是能够变得。也就是说单词之间仅仅要字母是一样的不用考虑顺序一样都要输出)。假设字典中沒有字母都同样的單詞就輸出“NOT A VALID
WORD”。並且每次都要輸出一行“******”;
解題思路:
map容器是一個一對一的向量容器(詳細了解http://blog.csdn.net/keshacookie/article/details/19847781)
>>> 首先。輸入一系列字典單詞,碰到“XXXXXX”結束;這些單詞作為向量的前端(後端也行。個人喜好,思路不要弄錯即可了)。 在每輸入一個字典單詞的時候。保存單詞的原態。 然後再對單詞排序,排序后的單詞作為向量的後端;
>>> 然後,輸入加密后的單詞,先對加密單詞進行排序,然後對map裡面存儲的字典單詞向量的後端進行比较(遍歷一遍就OK了)。
>>> 對應輸出即可了;
代碼例如以下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map> //加入map頭文件
#include <string>
#include <algorithm>
#define RST(N)memset(N, 0, sizeof(N))
using namespace std; int flag;
string s1, s2; //字符串容器;
map <string, string> mp; //map容器
map <string, string> ::iterator it; //map迭代器 int main()
{
mp.clear(); //清空map容器
while(cin >> s1) { //輸入字典單詞
if(s1 == "XXXXXX") break;
s2 = s1; //保存單詞的原來狀態
sort(s1.begin(), s1.end());
mp[s2] = s1; //s1, s2形成向量,存儲在map容器中
}
while(cin >> s1) { //輸入加密單詞
if(s1 == "XXXXXX") break;
flag = 0;
sort(s1.begin(), s1.end());
for(it=mp.begin(); it != mp.end(); it++) { //遍歷,對字符串進行比较
string tmp = (*it).second; //map中first。second分別代表向量的前後端
if(s1 == tmp) {
cout << (*it).first << endl;
flag = 1;
}
}
if(!flag) cout << "NOT A VALID WORD" << endl;
cout << "******" << endl;
}
return 0;
}
HDU 1113 Word Amalgamation (map 容器 + string容器)的更多相关文章
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
Problem Description In millions of newspapers across the United States there is a word game called J ...
- hdu 1113 Word Amalgamation
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...
- hdu - 1113 Word Amalgamation (stl)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典 ...
- hdu 1113 Word Amalgamation 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- hdu1113 Word Amalgamation(详解--map和string的运用)
版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...
- STL学习系列九:Map和multimap容器
1.map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...
- map,vector 等容器内容的循环删除问题(C++)
map,vector 等容器内容的循环删除问题(C++) map,vector等容器的循环删除不能用普通的方法删除: for(auto p=list.begin();p!=list.end();p++ ...
- STL之Map和multimap容器
1.Map和multimap容器 1)map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. 2)map中key值是唯一的.集合中的元素按一 ...
随机推荐
- javascript定义类或对象的方式
本文介绍的几种定义类或对象的方式中,目前使用最广泛的是:混合的构造函数/原型方式.动态原型方式.不要单独使用经典的构造函数或原型方式. 工厂方式 构造器函数 原型方式 混合的构造函数/原型方式 动态原 ...
- wampserver配置多站点
1.打开C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf(因安装的路径而异),查找listen 80 下面加上listen 8080 2.然后加上 < ...
- php保存远程图片
php获取远程图片并把它保存到本地 来源: 时间:2013-09-05 19:26:57 阅读数:45006 分享到:1 [导读] 在php中我们经常使用写一些简单的采集功能,这样可以自动把远 ...
- html5之文件操作
用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据.到目前文职,只有FF3.6+和Chrome6 ...
- 使用Aliyun Docker 容器镜像/注册表服务
1.前往阿里云容器镜像服务创建相关资源. 2.登录你的仓库,账户名+公共地址 docker login --username=xxxxxxxxx@aliyun.com registry.cn-hang ...
- docker(部署常见应用):docker部署nginx
上回说到centos安装docker. 这次用实战,docker部署运行常见的应用. docker常用命令 参看:docker命令大全.这里不做赘述. docker部署nginx 1.docker h ...
- EditPlus代码自动完成的设置
EditPlus代码自动完成的设置保存在 *.acp 文件中,可以在“工具”->“首选项”->“文件”->“文件类型及语法”中(如下图) 其中“语法文件”保存着进行语法高亮的关键词, ...
- Windows 下修改 MySQL 编码为 utf8
问题 Windows 下安装 MySQL 后,默认编码不全utf8. mysql> show variables like '%char%'; +------------------------ ...
- 使用Word 2010群发邮件
1.建立数据库,这里我使用了excel 字段:电子邮件地址,名字 填写需要发送的数据 2.新建word文档,这里我使用了word2010 点击工具栏邮件 开始邮件合并,电子邮件 选择收件人,使用现有列 ...
- wp8路线跟踪应用源码详细说明
目录 介绍 应用程序界面 定时执行 定位追踪 设置地图Pitch和Heading属性 后台位置追踪 Live Tile 总结 介绍 我从Windows Phone7 还在测试阶段的时候就开始开发了,所 ...