HDU 1075 What Are You Talking About (stl之map映射)
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 28482    Accepted Submission(s): 9710
Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
Output
In this problem, you have to output the translation of the history book.
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
Sample Output
hello, i'm from mars.
i like earth!
题意:将输入字符按照输入规则翻译
分析:利用map构成映射,遇到标点或者空格时将前部分字母串翻译输出即可
#include<iostream>
#include<map>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
         string  s1,s2;
         cin>>s1;//START
         map<string,string>m;
         while(cin>>s1&&s1!="END")
                  cin>>s2,m[s2]=s1;
         cin>>s1;//START
         char s[3003];
         getchar();//去掉空行
         while(gets(s))//cin.getline(s,3003))
         {
                  if(!strcmp(s,"END"))
                           break;
                  int len=strlen(s);
                  s2="";
                  for(int i=0;i<len;i++)
                  {
                           if(s[i]>='a'&&s[i]<='z')
                                    s2+=s[i];
                           else
                           {
                                    if(m[s2]!="")//输出字符串
                                             cout<<m[s2];
                                    else
                                             cout<<s2;
                                    printf("%c",s[i]);//输出符号
                                    s2="";
                           }
                  }
                  printf("\n");
         }
         return 0;
}HDU 1075 What Are You Talking About (stl之map映射)的更多相关文章
- HDU 1075 What Are You Talking About(Trie的应用)
		What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ... 
- hdu 1075 What Are You Talking About
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ... 
- C++ STL中Map的按Key排序和按Value排序
		map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区 分),我们用map来进 ... 
- STL中map与hash_map的比较
		1. map : C++的STL中map是使用树来做查找算法; 时间复杂度:O(log2N) 2. hash_map : 使用hash表来排列配对,hash表是使用关键字来计算表位置; 时间复杂度:O ... 
- STL中map,set的基本用法示例
		本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程. map的基本使用: #include "std ... 
- STL中map与hash_map容器的选择收藏
		这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ... 
- C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET
		C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET C++ STL中Map的相关排序操作:按Key排序和按Value排序 分类: C ... 
- STL之map排序
		描述 STL的map中存储了字符串以及对应出现的次数,请分别根据字符串顺序从小到大排序和出现次数从小到大排序. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { ... 
- STL中map的遍历
		map作为STL中的映射容器非常好用,我们来说一下map的遍历. map.first为key值,map.second为value值,key不可修改,value可修改. 定义一个迭代指针iter,使其指 ... 
随机推荐
- Pftriage:分析和追踪恶意文件,识别特征
			项目地址 PFTriage:https://github.com/idiom/pftriage 参考 Pftriage:如何在恶意软件传播过程中对恶意文件进行分析 https://www.freebu ... 
- LwIP Application Developers Manual8---Sample lwIP applications
			1.前言 你已经编译lwIP协议栈在你的目标平台上,并且网络驱动正常工作.你可以ping你的设备. 干得好,为你感到骄傲.虽然一个设备可以响应ping,但并不能算一个完整的应用. 现在你可以通过网络接 ... 
- k64 datasheet学习笔记50---GPIO
			1.前言 GPIO模块支持8bit 16bit 32bit访问,当被配置为GPIO功能时,GPIO数据方向和数据寄存器控制了每个引脚的输出方向和输出数据 不管GPIO配置为何种功能,GPIO输入寄存器 ... 
- js变量的解构赋值
			今天在学习时看到几段代码,让我感叹JS的灵活,特此一记: let stateObj = {a:1,b:3}; let newObj = {b:13,c:4} ; stateObj = {...stat ... 
- Linux内核很吊之 module_init解析 (下)【转】
			转自:https://blog.csdn.net/richard_liujh/article/details/46758073 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ... 
- 初探Linux内核中的内存管理
			Linux内核设计与实现之内存管理的读书笔记 初探Linux内核管理 内核本身不像用户空间那样奢侈的使用内存; 内核不支持简单快捷的内存分配机制, 用户空间支持? 这种简单快捷的内存分配机制是什么呢? ... 
- 安装python2、python3
			先安装python2: python安装 D:\Python27 目录下的 "python.exe" 重命名为 "python2.exe",则在cmd中输入 p ... 
- 漏洞扫描工具Nessu的安装和简单使用
			一.软件介绍Nessus号称是世界上最流行的漏洞扫描程序,全世界有超过75000个组织在使用它.该工具提供完整的电脑漏洞扫描服务,并随时更新其漏洞数据库.Nessus不同于传统的漏洞扫描软件,Ness ... 
- UVA 1395 MST
			给你一个图, 求一个生成树, 边权Max – Min 要最小,输出最小值, 不能构成生成树的 输出 -1: 思路: Keuksal 算法, 先排序边, 然后枚举 第一条边, 往后加入边, 直到有 n- ... 
- 浅谈深度优先和广度优先(scrapy-redis)
			首先先谈谈深度优先和广度优先的定义 深度优先搜索算法(英语:Depth-First-Search,DFS)是一种用于遍历或搜索树或图的算法.沿着树的深度遍历树的节点,尽可能深的搜索树的分支.当节点v的 ... 
