hdu1113 Word Amalgamation(详解--map和string的运用)
版权声明:本文为博主原创文章。未经博主同意不得转载。
vasttian https://blog.csdn.net/u012860063/article/details/35338617
转载请注明出处:http://blog.csdn.net/u012860063天资
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=1113
Word AmalgamationTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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; 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
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的运用)的更多相关文章
- poi导出word表格详解 超详细了
转:非常感谢原作者 poi导出word表格详解 2018年07月20日 10:41:33 Z丶royAl 阅读数:36138 一.效果如下 二.js代码 function export_word( ...
- 详解 Map集合
(请关注 本人"集合总集篇"博文--<详解 集合框架>) 首先,本人来讲解下 Map集合 的特点: Map集合 的特点: 特点: 通过 键 映射到 值的对象 一个 映射 ...
- java如何对map进行排序详解(map集合的使用)
今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单介绍Map 在讲解Map排 ...
- java 实现敏感词(sensitive word)工具详解使用说明
sensitive-word 平时工作中,只要涉及到用户可以自由发言(博客.文档.论坛),就要考虑内容的敏感性处理. sensitive-word 基于 DFA 算法实现的高性能敏感词工具.工具使用 ...
- 详解Map集合体系及方法entrySet、keySet、values
简单回顾Map集合: Map表示映射关系,以键值对的方式来保存数据.key和value一一对应.key是唯一的,不可重复,而value是可重复的,可以被多个key关联.虽然Map是放入两个数据,但是却 ...
- HDU1113 Word Amalgamation
Description In millions of newspapers across the United States there is a word game called Jumble. T ...
- Java基础:String类详解,案例用户登录实现,案例手机号截取实现,案例敏感词替换实现;StringBuilder类详解,StringBuilder和String相互转换,附练习案例.
1.API 1.1 API概述-帮助文档的使用 什么是API API (Application Programming Interface) :应用程序编程接口 java中的API 指的就是 JDK ...
- C++中的STL中map用法详解(转)
原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解 Map是STL的一个关联容器,它提供 ...
- STL map 常见用法详解
<算法笔记>学习笔记 map 常见用法详解 map翻译为映射,也是常用的STL容器 map可以将任何基本类型(包括STL容器)映射到任何基本类型(包括STL容器) 1. map 的定义 / ...
随机推荐
- FZU2168——防守阵地 I——————【找规律或前缀和】
防守阵地 I Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 判断当前IE浏览器是否支持JS
1.server 2008 r2 64位中自带的IE默认不支持js,这样一些有JS的页面就是失效,所以如果要考虑这方面的系统,需要判断浏览器是否支持JS <div class="js- ...
- Rsyslog+ELK日志分析系统搭建总结1.0(测试环境)
因为工作需求,最近在搭建日志分析系统,这里主要搭建的是系统日志分析系统,即rsyslog+elk. 因为目前仍为测试环境,这里说一下搭建的基础架构,后期上生产线再来更新最后的架构图,大佬们如果有什么见 ...
- 从 JDK 源码角度看 Object
Java的Object是所有其他类的父类,从继承的层次来看它就是最顶层根,所以它也是唯一一个没有父类的类.它包含了对象常用的一些方法,比如getClass.hashCode.equals.clone. ...
- 使用Having子句
Having 子句与where子句的功能类似,都是对行进行筛选.但是,where搜索条件是在分组操作之前对记录进行筛选,然后再由group BY 对筛选后符合条件的行进行分组:而Having搜索条件则 ...
- 微信小程序整理
目录 开发环境 目录结构 WXML组件 WXSS 数据绑定 条件渲染 列表渲染 模版 事件 引用 路由传参 API 实例TodoList 1.开发环境 开发工具下载(https://mp.weixin ...
- [PHP] Oauth授权和本地加密
1.Oauth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方 关键字:appKey appSecre ...
- Heka 的配置文件加载逻辑
Heka 使用的是 TOML 格式的配置文件, 有关 golang 加载 TOML 配置文件的技术请参看: http://www.cnblogs.com/ghj1976/p/4082323.html ...
- 解决vue移动端适配问题
1,先看看网上关于移动端适配讲解 再聊移动端页面适配,rem和vw适配方案! 基础点:rem相对根节点字体的大小.所以不用px; 根字体:字体的大小px; px:你就当成cm(厘米)这样的东西吧: 基 ...
- Hibernate 一对多,多对多,多对一检索策略
一.概述 我们先来谈谈检索数据时的两个问题: 1.不浪费内存 2.更好的检索效率 以上说的问题都是我们想要避免的,接下来就引出了我们要讨论的话题---------------hibernate检索 ...