Word Amalgamation

点我挑战题目

点我一起学习STL-MAP

题意分析

给出字典。之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输出,那么按照字典序将其输出。 若没有对应单词,输出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)的更多相关文章

  1. HDU 1113 Word Amalgamation (map 容器 + string容器)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...

  2. hdu Word Amalgamation(map)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 找单词 #include <iostream> #include <strin ...

  3. Word Amalgamation(hdoj1113)

    Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...

  4. HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)

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

  5. HDOJ.2094 产生冠军(map)

    产生冠军 点我挑战题目 点我一起学习STL-MAP 题意分析 给出n组数据,代表a打败了b,让判断根据这n组数据是否能判断出来产生了冠军.一开始以为这道题很难,其实用map可以应付. 大原则,赢了的人 ...

  6. HDOJ.2072 单词数(map)

    单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...

  7. 第二十七篇 玩转数据结构——集合(Set)与映射(Map)

          1.. 集合的应用 集合可以用来去重 集合可以用于进行客户的统计 集合可以用于文本词汇量的统计   2.. 集合的实现 定义集合的接口 Set<E> ·void add(E) ...

  8. GO语言总结(4)——映射(Map)

    上一篇博客介绍了Go语言的数组和切片——GO语言总结(3)——数组和切片,本篇博客介绍Go语言的映射(Map) 映射是一种内置的数据结构,用来保存键值对的无序集合. (1)映射的创建 make ( m ...

  9. 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; 要求完善设计,使得 ...

随机推荐

  1. 一对多,多的逗号分隔存在新字段中(Group_concat 用法)

    sql 语句: SELECT    (        SELECT            Group_concat(t_work_group_user.user_id)        FROM     ...

  2. python3读取csv文件

    代码如下 import csv with open('D:\\abc\\userinfo.csv',newline='') as f: reader = csv.reader(f) for row i ...

  3. 使用gitlab时候 fork仓库不会实时从主仓库更新解决方案

    付费用户可以使用现成的方案,地址见 链接 但是私有gitlab时候,需要手动进行如下操作 1. Clone your fork: git clone git@github.com:YOUR-USERN ...

  4. Django - day00 第一个页面

    Django - day00 0.写在最前面 第一次接触Django,是在大三的做数据库课程设计的时候,当时好像还是1.8的版本,现转眼就到了2.0的版本. 当时由于没太多的课,仅花了不到一周的时间就 ...

  5. 一篇文章让你了解GC垃圾回收器

    简单了解GC垃圾回收器 了解GC之前我们首先要了解GC是要做什么的?顾名思义回收垃圾,什么是垃圾呢? GC回收的垃圾主要指的是回收堆内存中的垃圾对象. 从根对象出发,所有被引用的对象,都是存活对象 其 ...

  6. OpenMPI源码剖析2:ompi_mpi_errors_are_fatal_comm_handler函数

    上一篇文章说道,初始化失败会有一个函数调用: ompi_mpi_errors_are_fatal_comm_handler(NULL, NULL, message); 所以这里简单地进入了 ompi_ ...

  7. windows store无法登陆的问题解决方案

    Windows应用商店或商店Apps无法打开或闪退的可选方法 (仅用于10565之前的Windows 10版本) 右键点击任务栏,选择"属性",切换到"导航"选 ...

  8. CSS动画@-webkit-keyframes

    @-webkit-keyframes:以百分比来规定改变发生的时间,或者通过关键词 "from" 和 "to",等价于 0% 和 100%.0% 是动画的开始时 ...

  9. struts2 result type属性说明

    首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-type name="chain" ...

  10. POJ 1873 The Fortified Forest(枚举+凸包)

    Description Once upon a time, in a faraway land, there lived a king. This king owned a small collect ...