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映射)的更多相关文章

  1. 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 ...

  2. hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...

  3. C++ STL中Map的按Key排序和按Value排序

    map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区 分),我们用map来进 ...

  4. STL中map与hash_map的比较

    1. map : C++的STL中map是使用树来做查找算法; 时间复杂度:O(log2N) 2. hash_map : 使用hash表来排列配对,hash表是使用关键字来计算表位置; 时间复杂度:O ...

  5. STL中map,set的基本用法示例

    本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程. map的基本使用: #include "std ...

  6. STL中map与hash_map容器的选择收藏

    这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ...

  7. C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET

    C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET C++ STL中Map的相关排序操作:按Key排序和按Value排序 分类: C ...

  8. STL之map排序

    描述 STL的map中存储了字符串以及对应出现的次数,请分别根据字符串顺序从小到大排序和出现次数从小到大排序. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { ...

  9. STL中map的遍历

    map作为STL中的映射容器非常好用,我们来说一下map的遍历. map.first为key值,map.second为value值,key不可修改,value可修改. 定义一个迭代指针iter,使其指 ...

随机推荐

  1. mysql for linux6.8单机版安装

    主机名以及hostname文件修改 vi /etc/hosts vi /etc/sysconfig/network hostname mysql01 系统参数修改 设置用户资源限制 vi /etc/s ...

  2. APACHE - CXF 入门详解

    ref: https://www.cnblogs.com/hoojjack/p/6724659.html

  3. Linxu基础知识:终端、终端模拟器、shell

    实验楼课程第二个实验的讲解部分出现了三个词,我不知道它们三个是什么关系.查阅了度娘,归纳如下: - 终端: 在UNIX/LINUX系统中,用户通过终端登录系统后得到一个Shell进程,这个终端就成为S ...

  4. 在Linux下误删文件后恢复【转】

    针对日常维护操作,难免会出现文件误删除的操作.大家熟知linux文件系统不同win有回收站,删除后的文件可以到垃圾箱寻回,要知道linux文件修复比较费劲,网络上面的文档也是五花八门.所以本次研究一种 ...

  5. vue生命周期学习(watch跟computed)

    1.watch钩子函数监听数据的变化 watch 的一个特点是,最初绑定的时候是不会执行的,要等到 firstName 改变时才执行监听计算. <div> <p>FullNam ...

  6. 华为交换机配置NTP服务端/客户端

    作者:邓聪聪 配置设备作为NTP服务器 单播客户端/服务器模式 # 配置NTP主时钟,层数为2. <HUAWEI> system-view [HUAWEI] ntp refclock-ma ...

  7. xtrabackup

    mysqldump备份方式是采用逻辑备份,其最大的缺陷就是备份和恢复速度都慢,对于一个小于50G的数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了.而使 ...

  8. MySQL联结查询和子查询

    2018-2-24 16:18:12 星期六 今天需要统计一个运营活动的数据, 涉及三个表, 分组比较多 活动描述: 每个人可以领取多张卡片,  好友也可以赠送其卡片, 20或40张卡片可以兑换一个奖 ...

  9. Django 笔记(四)模板标签 ~ 自定义过滤器

    模板标签: 标签在渲染的过程中提供任意的逻辑 语法: 由{% ... %} 和 {% end... %} 常用标签: with:类似取别名 模版继承: Django模版引擎中最强大也是最复杂的部分就是 ...

  10. ios NSTimer的强引用问题

    在一个controller中,使用 NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest ...