题目链接: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. volatile关键字解析&内存模型&并发编程中三概念

    原文链接: http://www.cnblogs.com/dolphin0520/p/3920373.html volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java5之前,它是一个 ...

  2. centos中w使用smbclient连接window出现:session setup failed: NT_STATUS_LOGON_FAILURE

    1. 在window中网络->我自己的电脑->能够查看到共享文件,说明window的共享是正常了; 2. 在window中配置共享时,使用的是仅仅同意超级管理员訪问,可是我把超级管理员改名 ...

  3. mysql字段A复制到字段B,并替换指定字符

    ',字段a); eg:update `hy_b_pro` set goldWeight=jinJinZhong;

  4. 【转】如何查看Oracle客户端版本及位数(Windows系统)

    一.方法一 查看oracle客户端版本:sqlplus -v 查看oracle客户端版本:sqlplus /nolog命令 Step 1:运行sqlplus /nolog命令,如果你服务器安装了多个客 ...

  5. C++标准I/O库:iostream, fstream, sstringstream

    在写代码的过程中.我们最常做的事就是io操作,不管是对控制台,还是文件.但一段时间不写代码就忘了,这里理一下C++标准I/O库的详细类和操作. C++的标准I/O库包含我们常常使用的iostream, ...

  6. IPython与Jupyter notebook 安装与配置,插件扩展,主题,PDF输出

    基于 python2.7.13 32-bit版本安装 1.安装pyreadline https://pypi.python.org/pypi/pyreadline 下载对应的32位版本 安装Micro ...

  7. 设置清除html5页面缓存

    设置清除html5页面缓存 html5端设置 meta 标签: <meta http-equiv="Pragma" content="no-cache" ...

  8. 2016/05/25 empty() 与 isset()的区别

    对于初学php的人来说,empty()和和isset()用法的区别是很难搞清楚的,他们的用法的差别不仔细去琢磨的话确实很难弄清楚. 先说一下他们的共同点: 都可以判定一个变量是否为空: 都返回bool ...

  9. mongodb07---用户权限

    用户管理: 注意: 添加用户后,我们再次退出并登陆,发现依然可以直接读数据库? 原因: mongodb服务器启动时, 默认不是需要认证的. 要让用户生效, 需要启动服务器时,就指定 --auth 选项 ...

  10. HDU4612 Warm up —— 边双联通分量 + 重边 + 缩点 + 树上最长路

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4612 Warm up Time Limit: 10000/5000 MS (Java/Ot ...