HDOJ.1113 Word Amalgamation(map)
Word Amalgamation
题意分析
给出字典。之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输出,那么按照字典序将其输出。 若没有对应单词,输出NOT A VALID WORD。
可见这是一组组对应关系,可以用map来实现。map字典中first保存原本的单词(因为first按字典序),second保存原本单词排序后的单词。每次读入一个乱序单词后,sort遍历map并查找和second匹配的NODE,并输出其first即可。
代码总览
/*
Title:HDOJ.1113
Author:pengwill
Date:2016-11-21
*/
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
string s,b,str;
typedef map<string,string> mp;
mp p;
int main()
{
cin.sync_with_stdio(false);
cin.tie(0);
freopen("in.txt","r",stdin);
int t = 0;
while(cin>>str){
if(str.compare("XXXXXX") == 0 && t== 0){
t++;
}else if(str.compare("XXXXXX") == 0 && t== 1){
break;
}else if(!t){
//读入字典
s = b = str;
sort(b.begin(),b.end());
p[s] = b;
}else if(t){
//输出结果
int judge = 0;
s = str;
sort(s.begin(),s.end());
mp::iterator iter;
for(iter = p.begin() ; iter!=p.end() ; iter++){
//cout<<iter->first<<"\t"<<iter->second<<endl;
if(iter->second == s){
cout<<iter->first<<endl;
judge = 1;
}
}
if(judge){
cout<<"******"<<endl;
}else{
cout<<"NOT A VALID WORD"<<endl<<"******"<<endl;
}
}
}
return 0;
}
HDOJ.1113 Word Amalgamation(map)的更多相关文章
- HDU 1113 Word Amalgamation (map 容器 + string容器)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...
- hdu Word Amalgamation(map)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 找单词 #include <iostream> #include <strin ...
- Word Amalgamation(hdoj1113)
Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
Problem Description In millions of newspapers across the United States there is a word game called J ...
- HDOJ.2094 产生冠军(map)
产生冠军 点我挑战题目 点我一起学习STL-MAP 题意分析 给出n组数据,代表a打败了b,让判断根据这n组数据是否能判断出来产生了冠军.一开始以为这道题很难,其实用map可以应付. 大原则,赢了的人 ...
- HDOJ.2072 单词数(map)
单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...
- 第二十七篇 玩转数据结构——集合(Set)与映射(Map)
1.. 集合的应用 集合可以用来去重 集合可以用于进行客户的统计 集合可以用于文本词汇量的统计 2.. 集合的实现 定义集合的接口 Set<E> ·void add(E) ...
- GO语言总结(4)——映射(Map)
上一篇博客介绍了Go语言的数组和切片——GO语言总结(3)——数组和切片,本篇博客介绍Go语言的映射(Map) 映射是一种内置的数据结构,用来保存键值对的无序集合. (1)映射的创建 make ( m ...
- Java-集合=第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: List list = new ArrayList(); list.add(new A
第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得 ...
随机推荐
- 多台服务器下同步文件夹数据(rsync+inotify)
网上有很多讲解rsync+inotify的教程,我就先贴出一个来大家去看吧,基本都是类似的. http://www.jb51.net/article/57011.htm 我就强调几点,按照上面的方法配 ...
- pip源设置 & pandas安装
pip的官方源python.pypi.org貌似被墙,换用国内安装源 网上的设置方法都是基于Unix的,Windows下的设置略麻烦. 更新..\Lib\site-packages\pip下的cmdo ...
- 接口测试工具postman(五)批量执行测试用例
1.准备好测试用例及相关数据 2.点击Run按钮 3.选择运行collection或者folder 4.运行完成
- lintcode101 删除排序数组中的重复数字 II
删除排序数组中的重复数字 II 跟进“删除重复数字”: 如果可以允许出现两次重复将如何处理? 在:lintcode100删除排序数组中的重复数字 的基础上进行改进. class Solution ...
- 【第三章】MySQL数据库的字段约束:数据完整性、主键、外键、非空、默认值、自增、唯一性
一.表完整性约束 作用:用于保证数据的完整性和一致性==============================================================约束条件 说明PRIM ...
- POJ 1113 Wall(计算几何の凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- Alpha发布文案加美工展示
目录 团队简介 项目进展 组内分工 队员总结 后期计划 一.团队简介 二.项目进展 从选题发布到今天的Alpha发布,我们团队经历了许许多多的磨难.我们最终设计了如下的功能:首页.班级.个人.更多.打 ...
- 11.24Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.990 测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.991 测试 王宇杰 负责后台代码测 ...
- html .net 网页,网站标题添图标
<link rel="icon" href="../favicon.ico" type="image/x-icon" /> &l ...
- js实现倒计时60秒的简单代码
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...