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;
}
 

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

  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): 最大似然估计提供了一种给定观察数据来评估模型参数的方法,即:“模型已定,参数未知”.可以通过采样,获取部分数据,然后通过最大似然估计来获取已知模型的参数. 最大似然估计 ...

随机推荐

  1. Lodop打印控件指定打印任务某几页

    使用Lodop打印控件进行打印开发,有时候一个任务里有多页,例如各种合同之类的,客户端用户在使用过程中,可能有某一页打印后发现需要修改,这时候不必再把整个任务重新打印一遍,只需要打印需要修改的那页重新 ...

  2. 今天开始学习模式识别与机器学习Pattern Recognition and Machine Learning (PRML),章节5.1,Neural Networks神经网络-前向网络。

    话说上一次写这个笔记是13年的事情了···那时候忙着实习,找工作,毕业什么的就没写下去了,现在工作了有半年时间也算稳定了,我会继续把这个笔记写完.其实很多章节都看了,不过还没写出来,先从第5章开始吧, ...

  3. ADO.NET工具类(一)

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  4. Codeforces Round #459 Div. 1

    C:显然可以设f[i][S]为当前考虑到第i位,[i,i+k)的状态为S的最小能量消耗,这样直接dp是O(nC(k,x))的.考虑矩阵快速幂,构造min+转移矩阵即可,每次转移到下一个特殊点然后暴力处 ...

  5. Python中csv模块解析

    导入模块 import csv 2.读取csv文件 file1 = open('test1.csv', 'rb') reader = csv.reader(file1) rows = [row for ...

  6. Shell 字符截取命令 awk

    awk命令# awk '条件1{动作1} 条件2{动作2}….' 文件名一般使用关系表达式作为条件动作:1.格式化输出 2.流程控制语句 处理cut命令无法截取空格的列 例子:截取出磁盘使用率 df ...

  7. 用keras实现基本的图像分类任务

    数据集介绍 fashion mnist数据集是mnist的进阶版本,有10种对应的结果 训练集有60000个,每一个都是28*28的图像,每一个对应一个标签(0-9)表示 测试集有10000个 代码 ...

  8. 使用unittest单元测试框架对加法做单元测试

    import unittest from parameterized import parameterized def cacl(a, b): return a+b class MyCacl(unit ...

  9. LaTeX教程与下载

    LaTeX教程与下载如下: 其实,下载好CTEX 的步骤只有三步.第一步下载好CTEX ,第二步下载编辑器Texstudio ,第三步安装配置TexStudio 详细步骤: 第一步:下载CTEX La ...

  10. bzoj4337树的同构

    树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如果能够把树T1的所有点重 ...