题目链接: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. Android Studio 经常使用手冊

    经常使用小操作 单词选择 显示近期操作 改动的文件 文件查找 操作记录 移动行 查找方法调用处 方法的跟进 显示方法的參数 行的高速操作 多行操作 高速补全完毕 代码提示 变量的高速操作 代码折叠 预 ...

  2. Reload file in vim

    68down voteaccepted Give this a try: :e From :h :e: Edit the current file. This is useful to re-edit ...

  3. Android时时监測手机的旋转角度 依据旋转角度确定在什么角度载入竖屏布局 在什么时候载入横屏布局

    一.场景描写叙述: 最近开发中遇到个问题,就是我们在做横竖屏切换的功能时.横竖屏布局是操作系统去感知的,作为开发员没法确定Activity在什么时候载入横屏布局,在什么时候载入竖屏布局.因此为了找到载 ...

  4. hdu 4950 Monster(数学题,多校8)

    题目链接:pid=4950http://acm.hdu.edu.cn/showproblem.php?pid=4950">http://acm.hdu.edu.cn/showprobl ...

  5. C#使用SharpZipLib压缩解压文件

    #region 加压解压方法 /// <summary> /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件,文件夹及其子级被忽略) /// </summary> // ...

  6. Spring学习笔记——Spring中lazy-init与abstract具体解释

    Spring的懒载入的作用是为了避免无谓的性能开销,就是当真正须要数据的时候才去运行数据的载入操作.不只在Spring中.我们在实际的编码过程中也应该借鉴这种思想,来提高我们程序的效率. 首先我们看一 ...

  7. Oracle 模糊查询方法

           在这个信息量剧增的时代,怎样帮助用户从海量数据中检索到想要的数据.模糊查询是不可缺少的. 那么在Oracle中模糊查询是怎样实现的呢?   一.我们能够在where子句中使用likeke ...

  8. RabbitMQ通过shovel插件迁移数据

    前言 生产环境中会遇到RabbitMQ数据迁移的场景,例如:切换云服务厂商.不同Region之间数据迁移.新搭建RabbitMQ实例,数据需要同步至新的RabbitMQ实例. 前提条件: 源Rabbi ...

  9. Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu

    While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or ...

  10. 2016/2/24 1,dotctype有几种? 2,了解html的发展历史

    1,dotctype有几种?DOCTYPE是document type(文档类型)的简写,用来说明你用的XHTML或者HTML是什么版本. 其中的DTD(例如上例中的xhtml1-transition ...