题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075

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!

问题描述

   伊格内修斯非常幸运,昨天他遇到了火星人。但他不知道火星人使用的语言。火星人离开时给他一本火星历史书和一本字典。现在伊格内修斯想把历史书翻译成英文。你能帮助他吗?

输入

  这个问题只有一个测试用例,测试用例由两部分组成,即字典部分书本部分。字典部分以单行开头,包含一个字符串“START”,这个字符串应该被忽略,接下来是一些行,每行包含两个字符串,第一个是英文单词,第二个是火星人的相应单词语言。具有单个字符串“END”的行表示目录部分的结束,并且该字符串应该被忽略。本书部分以单行开头,包含一个字符串“START”,这个字符串应该被忽略,然后是一篇用火星文写成的文章。你应该用字典将文章翻译成英文。如果你在字典中找到这个单词,你应该翻译它,并将新单词入你的翻译中,如果你无法在字典中找到这个单词,你就需要翻译它,只需将旧单词复制到你的翻译中。空格(''),选项卡('\ t'),输入('\ n')和所有标点不应该被翻译。(不是英文的字符原样输出)带有单个字符串“END”的行表示书籍部分的结尾,这也是输入的结尾。所有单词都是小写字母,每个单词最多包含10个字符,每行最多包含3000个字符。

输出

在这个问题中,你必须输出历史书的翻译。

解题思路: 此题有两种解法:map解法+Trie解法。这里提供map解法。题目说得很清楚,给出书本部分,去找字典中的翻译并输出,这种键值很容易想到map关联式容器,用火星单词做key,英文单词做value,用find来查找字典,这样处理就简单多了。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
map<string,string>mp;
int main()
{
mp.clear();//清空map容器
string s1,s2;
cin>>s1;//输入START,不需要吸收换行符,因为上下均为cin输入字符串
while(cin>>s1){
if(s1=="END")break;
cin>>s2;
mp[s2]=s1;//映射建立字典键值
}
cin>>s1;//读入START
char ch=getchar();//吃掉回车符的影响,因为下一个读取的是单个字符
while(){
s1="";//重新将s1赋值为空字符串,用来记录单词的字符串
while(){
scanf("%c",&ch);//每次读取当前字符
if(!((ch>='a' && ch<='z')||(ch>='A' && ch<='Z')))break;//只要不是英文字母就直接退出,即为一个单词
s1+=ch;//加进来作为一个单词
}
if(s1=="END")break;//如果是END的话就直接退出循环
if(mp.find(s1)==mp.end())cout<<s1;//当迭代器指向尾后迭代器表明找不到,原样输出火星字符串
else cout<<mp[s1];//否则输出字典单词
printf("%c",ch);//输出不是字母的字符
}
return ;
}

题解报告:hdu 1075 What Are You Talking About的更多相关文章

  1. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  2. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  3. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

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

  5. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

  6. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

  7. cojs 二分图计数问题1-3 题解报告

    OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...

  8. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  9. CF1169(div2)题解报告

    CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...

  10. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

随机推荐

  1. 【APUE】进程间通信之共享存储(mmap函数)

    共享内存可以说是最有用的进程间通信方式,也是最快的IPC形式,因为进程可以直接读写内存,而不需要任何数据的拷贝.对于像管道和消息队列等通信方式,则需要在内核和用户空间进行四次的数据拷贝,而共享内存则只 ...

  2. MySQL Study之--Percona Server版本号

    MySQL Study之--Percona Server版本号 1.简单介绍      Percona 为 MySQL 数据库server进行了改进.在功能和性能上较 MySQL 有着非常显著的提升. ...

  3. COCOS2DX学习之Box2d物理引擎使用之------动态物体的创建

    1.创建一个物理世界 首先要引入一个头文件#include "Box2D\Box2D.h" 之后利用b2word创建一个对象,而且指定这个物理世界中的加速度方向. word = n ...

  4. 【Mongodb教程 第一课 补加课1 】windows7 下安装mongodb 开启关闭服务

    mongodb在2.2版本开始就不支持windows xp了(我想现在用xp的应该也是带着情怀的一部分人吧,我只是一个工匠而已),windows下server8 R2,64位,32位,只是32位只支持 ...

  5. 用CSS画小猪佩奇,你就是下一个社会人! js将“I am a coder”反转成 “coder a am I”,不许用split,join,subString,reverse;求解方法三

    用CSS画小猪佩奇,你就是下一个社会人!   欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 作者:江志耿 | 腾讯TEG网络工程师 我是佩奇,哼,这是我的弟弟乔治,呱呱,这是我的妈妈,嚯 ...

  6. 使用Blender批量导出/转换模型

    2.4版本号的Blender API和2.5以上版本号的API有非常大的不同,这里仅仅是提供了思路和2.4版本号的导出方案. 先提供一个脚本,这个是由Blender调用的.用于转换Ogre的Mesh文 ...

  7. HDU 4897 Little Devil I 树链剖分+线段树

    Little Devil I Problem Description There is an old country and the king fell in love with a devil. T ...

  8. struts2的(S2-045,CVE-2017-5638)漏洞测试笔记

    网站用的是struts2 的2.5.0版本 测试时参考的网站是http://www.myhack58.com/Article/html/3/62/2017/84026.htm 主要步骤就是用Burp ...

  9. 初识NodeJS服务端开发(Express+MySQL)

    http://www.alloyteam.com/2015/03/sexpressmysql/

  10. 搭建基于Maven的SSM框架

    先展示文件结构图对工程结构有大致了解: 主要为  ssm-parent (用来管理jar包版本)是每个工程的父工程,ssm-common(用来处理底层数据),ssm-manager(对数据库信息进行操 ...