What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 25683 Accepted Submission(s): 8745
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 fiwohello difhmars riwosfearth fnnvklike 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 <cctype>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
string a, b;
string s;
map<string, string> mp;
int main() {
cin >> a;
while (cin >> a) {
if (a == "END")
break;
cin >> b;
mp[b] = a;
}
cin >> a;
getchar();
while (1) {
getline(cin,s);
if (s=="END")
break;
int len = s.length(); //确定输入的字符串的长度。
a = ""; //对字符串a初始化。
for(int i=0;i<len;i++) {
if (islower(s[i])) {
a += s[i];
} else {
if (mp.find(a) != mp.end())
cout << mp[a];
else
cout << a;
a = ""; //对字符串进行初始化。
cout << s[i]; //还需要输出s[i],s[i]不是小写字母,要考虑这个可能性。
}
}
cout << endl;
}
return 0;
}
方法二:
#include <cctype>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
string a, b;
string s;
map<string, string> mp;
int main() {
cin >> a;
while (cin >> a) {
if (a == "END")
break;
cin >> b;
mp[b] = a;
}
cin >> a;
getchar();
while (1) {
getline(cin,s);
if (s=="END")
break;
int len = s.length();
a = "";
for(int i=0;i<len;i++) {
if (islower(s[i])) {
a += s[i];
} else {
if (mp[a]=="") //也可以这样用。
cout<<a;
else
cout<<mp[a];
a = "";
cout << s[i];
}
}
cout << endl;
}
return 0;
}
- GO语言总结(4)——映射(Map)
上一篇博客介绍了Go语言的数组和切片——GO语言总结(3)——数组和切片,本篇博客介绍Go语言的映射(Map) 映射是一种内置的数据结构,用来保存键值对的无序集合. (1)映射的创建 make ( m ...
- 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; 要求完善设计,使得 ...
- Java-map-第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录
第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
- 第一题 (Map)利用Map,完成下面的功能:
从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年份,请参考本章附录. 附录 1.历届世界杯冠 ...
- 【机器学习基本理论】详解最大似然估计(MLE)、最大后验概率估计(MAP),以及贝叶斯公式的理解
[机器学习基本理论]详解最大似然估计(MLE).最大后验概率估计(MAP),以及贝叶斯公式的理解 https://mp.csdn.net/postedit/81664644 最大似然估计(Maximu ...
- 【机器学习基本理论】详解最大后验概率估计(MAP)的理解
[机器学习基本理论]详解最大后验概率估计(MAP)的理解 https://blog.csdn.net/weixin_42137700/article/details/81628065 最大似然估计(M ...
- GoLang基础数据类型--->字典(map)详解
GoLang基础数据类型--->字典(map)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 可能大家刚刚接触Golang的小伙伴都会跟我一样,这个map是干嘛的,是 ...
- 列表生成式+过滤器(filter)+映射(map)+lambda总结
这些都是python的特色,不仅强大,而且好用,配合起来使用更是无敌. 零.lambda lambda用于产生一个匿名表达式,组成部分为:lambda + ‘函数表达式’ ‘函数表达式’由一个冒号加上 ...
- 最大似然估计(MLE)与最大后验概率(MAP)
何为:最大似然估计(MLE): 最大似然估计提供了一种给定观察数据来评估模型参数的方法,即:“模型已定,参数未知”.可以通过采样,获取部分数据,然后通过最大似然估计来获取已知模型的参数. 最大似然估计 ...
随机推荐
- TP5系统变量输出
1.超全局变量 模板中: {$Think.sever.server_name} //全部小写,输出blog.cn 控制器: $_SERVER['SERVER_NAME'] ...
- Windows & RabbitMQ:安装
可以参考:在 Windows 上安装Rabbit MQ 指南 本文RabbitMQ版本为3.6.1 Step 1:安装Erlang Step 2:安装RabbitMQ Step 3:启用Managem ...
- hdu-1251(字典树)
字典树模板题. ps:数组要开大,40w左右才行,不然疯狂re 代码: #include<iostream> #include<algorithm> #include<c ...
- 配置 Django
Django项目的设置文件位于项目同名目录下,名叫settings.py.这个模块,集合了整个项目方方面面的设置属性,是项目启动和提供服务的根本保证. 一.简述 settings.py文件本质上是一个 ...
- Qt QTimer
QTimer类提供了重复和单次触发信号的定时器. QTimer类为定时器提供了一个高级别的编程接口.很容易使用:首先,创建一个QTimer,连接timeout()信号到适当的槽函数,并调用start( ...
- Codeforces 714A 朋友聚会
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395268.html A. Meeting of Old Friends time limit p ...
- Spring 学习笔记(二)
spring 核心 (xml方式.注解方式) 两种方式实现 ioc :控制反转 aop : 面向切面
- bzoj 2588 : Spoj 10628. Count on a tree
Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始 ...
- MT【258】椭圆第三定义
如图,已知椭圆方程为$\dfrac{x^2}{4}+\dfrac{y^2}{3}=1$$A$为椭圆上一点,$AF_1,AF_2$与椭圆交于$B,C$两点,$A_1B,A_2C$交于一点$M$.当$A$ ...
- HAOI2017 简要题解
「HAOI2017」新型城市化 题意 有一个 \(n\) 个点的无向图,其中只有 \(m\) 对点之间没有连边,保证这张图可以被分为至多两个团. 对于 \(m\) 对未连边的点对,判断有哪些点对满足将 ...