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? 

InputThe 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. 
OutputIn 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!

Hint

Huge input, scanf is recommended.
本题相当于翻译句子;
#include<iostream>
#include<map>
#include<string >
using namespace std;
int main()
{
map <string, string> mp;
string str, temp;
cin >> str;
while (cin >> str && str != "END")
{
cin >> temp;
mp[temp] = str;
}
cin >> str;
getchar();
while (getline(cin, str) && str != "END")
{
string st = "";
for (int i = ; i < str.length(); i++)
{
if (!isalpha(str[i]))
{
map<string, string>::iterator p = mp.find(st);
if (p == mp.end()) cout << st;
else cout << mp[st];
cout << str[i];
st = "";
}
else
st += str[i];
}
cout << endl;
}
return ;
}

利用map<string,string>解决;注意的是放在map中的first,second位置的不同,而引起的find的不同;

灵活应用map

What Are You Talking About (map)的更多相关文章

  1. GO语言总结(4)——映射(Map)

    上一篇博客介绍了Go语言的数组和切片——GO语言总结(3)——数组和切片,本篇博客介绍Go语言的映射(Map) 映射是一种内置的数据结构,用来保存键值对的无序集合. (1)映射的创建 make ( m ...

  2. Java-集合=第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: List list = new ArrayList(); list.add(new A

    第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得 ...

  3. Java-map-第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录

    第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...

  4. 第一题 (Map)利用Map,完成下面的功能:

    从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯.  附:世界杯冠军以及对应的夺冠年份,请参考本章附录. 附录  1.历届世界杯冠 ...

  5. 【机器学习基本理论】详解最大似然估计(MLE)、最大后验概率估计(MAP),以及贝叶斯公式的理解

    [机器学习基本理论]详解最大似然估计(MLE).最大后验概率估计(MAP),以及贝叶斯公式的理解 https://mp.csdn.net/postedit/81664644 最大似然估计(Maximu ...

  6. 【机器学习基本理论】详解最大后验概率估计(MAP)的理解

    [机器学习基本理论]详解最大后验概率估计(MAP)的理解 https://blog.csdn.net/weixin_42137700/article/details/81628065 最大似然估计(M ...

  7. GoLang基础数据类型--->字典(map)详解

    GoLang基础数据类型--->字典(map)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   可能大家刚刚接触Golang的小伙伴都会跟我一样,这个map是干嘛的,是 ...

  8. 列表生成式+过滤器(filter)+映射(map)+lambda总结

    这些都是python的特色,不仅强大,而且好用,配合起来使用更是无敌. 零.lambda lambda用于产生一个匿名表达式,组成部分为:lambda + ‘函数表达式’ ‘函数表达式’由一个冒号加上 ...

  9. 最大似然估计(MLE)与最大后验概率(MAP)

    何为:最大似然估计(MLE): 最大似然估计提供了一种给定观察数据来评估模型参数的方法,即:“模型已定,参数未知”.可以通过采样,获取部分数据,然后通过最大似然估计来获取已知模型的参数. 最大似然估计 ...

  10. 从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射

    从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射.Collection 接口又有 3 ...

随机推荐

  1. Java基础_0306:数组的定义与使用

    数组 数组指的就是一组相关变量的集合.例如:如果说现在要想定义100个整型变量,按照传统的思路,可能这样定义: int i1,i2 ,... i100,一共写100个变量. 以上的形式的确可以满足技术 ...

  2. 简单的复用accep

    s = socket.socket() adress = ("192.168.15.102", 9999) s.bind(adress) s.listen() s.setblock ...

  3. 将数据以json字符串格式传到前台请求页面

    1.前台ajax方法(这个是在FlowDocAction的add.jsp页面) //序列号 var preFileNo = factoryCode+deptCode+"-"+mod ...

  4. 如何在 JS 中嵌入大量 HTML 代码 --更新2017-10-10 16:37:09

    一.一般方式 方式1:\ 要写在标签后面,看例子 var longString = "\ ------------------------\ ------------------------ ...

  5. 2017-2018-2 20165234 实验三 《Java面向对象程序设计》实验报告

    实验三 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA 参考 http://www.cnblogs. ...

  6. CentOS 7 安装配置 Vsftpd

    https://blog.imzhengfei.com/centos-an-zhuang-pei-zhi-vsftpd/ vsftpd 是“very secure FTP daemon”的缩写,是一款 ...

  7. zookeeper的ACL权限控制

    ACL:Access Control List  访问控制列表 1.  简介 0.概述 ACL 权限控制,使用:scheme:id:perm 来标识,主要涵盖 3 个方面: 权限模式(Scheme): ...

  8. cisco和华为的设备如何设置命令不分页显示

    作者:邓聪聪 为了登陆设备查看信息没有分页,cisco和华为的设备上可以设置不分页显示 Cisco: > terminal length HUAWEI / H3C: > user-inte ...

  9. springcloud-2:服务中心(1)

    环境:springboot 2.0.0 + springcloud Finchley.M9 pom.xml: <?xml version="1.0" encoding=&qu ...

  10. Git操作----删除untracked files

    # 删除 untracked files git clean -f # 连 untracked 的目录也一起删掉 git clean -fd # 连 gitignore 的untrack 文件/目录也 ...