题目链接: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. HOST绑定和VIP映射

    今天上线需要配置RAL,处理半天,发现是需要HOST和IP分开来配. 比如: curl -H "Host: ktvin.nuomi.com" "http://10.207 ...

  2. javascript闭包诡异的问题

    var funcs = []; for (var i = 0; i < 3; i++) { // let's create 3 functions funcs[i] = function() { ...

  3. 微信小程序 自定义组件(modal) 引入组件

    项目结构: 步骤一:创建组件 声明这一组文件为自定义组件 modal.json { "component": true, // 自定义组件声明 "usingCompone ...

  4. Linux VPS/server上用Crontab来实现VPS自己主动化

    VPS或者server上常常会须要VPS或者server上常常会须要定时备份数据.定时运行重新启动某个服务或定时运行某个程序等等,一般在Linux使用Crontab,Windows以下是用计划任务(W ...

  5. C语言 字符串操作 笔记

    /* C语言字符串的操作笔记 使用代码和注释结合方式记录 */ # include <stdio.h> # include <string.h> int main(void) ...

  6. HDU 3469 Catching the Thief (博弈 + DP递推)

    Catching the Thief Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. Servlet学习总结,为理解SpringMVC底层做准备

    Servlet 一句话概括 :处理web浏览器,其他HTTP客户端与服务器上数据库或其他应用交互的中间层 Servlet 生命周期 : 1.类加载, 2.实例化并调用init()方法初始化该 Serv ...

  8. Cron Expression

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...

  9. JavaScript中面向对象那点事

    鉴于自己在JavaScript这方面比較薄弱.所以就找了一本书恶补了一下(被称为犀利书的JavaScript权威指南).书的内容尽管多了点,但这也充分说明了js中的东西还是挺多的.尽管我们的定位不是前 ...

  10. django flask缓存memcache的key生成方法介绍

    去年的一个django项目中,使用了memcache作为系统缓存,并实现多台机器上的缓存共享.配置的cache如下图所示: 最近在项目调试过程中,发现memcache在进行缓存时,使用的key并不是实 ...