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!

Hint

 Huge input, scanf is recommended. 

map存储字符数组比较麻烦
所以用map存储string 两个string一一对应 只能用cin输入
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include <map>
using namespace std;
int main()
{
map<string,string>mapDic;
string a,b,c;
cin>>c;
while(cin>>a&&a!="END"){
cin>>b;
mapDic[b]=a;
}
cin>>c;
getchar();
char s[];
while(){
gets(s);
if(strcmp(s,"END")==)break;
int n=strlen(s);
b="\0";
for(int i=;i<n;i++){
if(s[i]>='a'&&s[i]<='z')b+=s[i]; //s[i]是字母,就将其存入string b中
else{ //若是s[i]不为字母
if(mapDic[b]!="\0")cout<<mapDic[b]; //就判断b是否可以用map转化地球语言 可以得话输出地球语言
else cout<<b; //不可以直接输出b
b="\0"; //清零b
printf("%c",s[i]); //不为字母 输出字符s[i]
}
}
printf("\n");
}
//system("pause");
return ;
}

T - stl 的mapⅡ的更多相关文章

  1. C++ STL中Map的按Key排序和按Value排序

    map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区 分),我们用map来进 ...

  2. STL中map与hash_map的比较

    1. map : C++的STL中map是使用树来做查找算法; 时间复杂度:O(log2N) 2. hash_map : 使用hash表来排列配对,hash表是使用关键字来计算表位置; 时间复杂度:O ...

  3. STL中map,set的基本用法示例

    本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程. map的基本使用: #include "std ...

  4. STL中map与hash_map容器的选择收藏

    这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ...

  5. C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET

    C++ STL中Map的相关排序操作:按Key排序和按Value排序 - 编程小径 - 博客频道 - CSDN.NET C++ STL中Map的相关排序操作:按Key排序和按Value排序 分类: C ...

  6. STL之map排序

    描述 STL的map中存储了字符串以及对应出现的次数,请分别根据字符串顺序从小到大排序和出现次数从小到大排序. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { ...

  7. C++中的STL中map用法详解(转)

    原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解   Map是STL的一个关联容器,它提供 ...

  8. C++ STL中Map的按Key排序跟按Value排序

    C++ STL中Map的按Key排序和按Value排序 map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定 ...

  9. [STL] Implement "map", "set"

    练习热身 Ref: STL中map的数据结构 C++ STL中标准关联容器set, multiset, map, multimap内部采用的就是一种非常高效的平衡检索二叉树:红黑树,也成为RB树(Re ...

  10. stl中map的四种插入方法总结

    stl中map的四种插入方法总结方法一:pair例:map<int, string> mp;mp.insert(pair<int,string>(1,"aaaaa&q ...

随机推荐

  1. JS正则表达式---分组

    JS正则表达式---分组 之前写了一篇关于正则新手入门的文章,本以为对正则表达式相对比较了解 但是今天我又遇到了一个坑,可能是自己不够细心的原因吧,今天就着重和大家分享一下javascript正则表达 ...

  2. POJ 2455 Secret Milking Machine (二分 + 最大流)

    题目大意: 给出一张无向图,找出T条从1..N的路径,互不重复,求走过的所有边中的最大值最小是多少. 算法讨论: 首先最大值最小就提醒我们用二分,每次二分一个最大值,然后重新构图,把那些边权符合要求的 ...

  3. 2、Khala的安装

    于2016年3月24日更新: 一.安装: 1.从github库下载源码https://github.com/moyangvip/khala 2.Khala采用CMake为build system,安装 ...

  4. (原)lua提示cannot load incompatible bytecode

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5754872.html 前段时间用终端和zerobrane运行torch的lua程序.zerobrane ...

  5. jQuery UI Datepicker&Datetimepicker添加 时-分-秒 并且,判断

    jQuery UI Datepicker时间(年-月-日) 相关代码: <input type="text" value="" name="ad ...

  6. 清空DNS缓存

    昨天写了个Python的脚本,功能就是爬取一个网页上的Google ip地址再写入到本机的hosts里面去. 但是写完并且运行完成之后发现上不了Google.于是想到了是不是要清空一下DNS的缓存.不 ...

  7. Roads in Berland(图论)

    Description There are n cities numbered from 1 to n in Berland. Some of them are connected by two-wa ...

  8. JS中各种宽度、高度、位置、距离总结

    1.window.screen 浏览器与屏幕的距离,screenX(screenLeft),screenY(screenTop) 2.window.scrollTo(x,y) 将纵向滚动条移动到相对于 ...

  9. Effective Java单元测试TestNG - 就是爱Java

    TestNG是另一种单元测试的framework,与JUnit的类似,这次Mix将使用它来撰写测试程序,大部分所引用的class package都一样,只差在JUnit与TestNG的字样,可以直接用 ...

  10. 十一、外观(Facade)模式--结构模式(Structural Pattern)

    外部与一个子系统的通信必须通过一个统一的门面(Facade)对象进行,这就是门面模式.门面模式要求一个子系统的外部与其内部的通信必须通过一个统一的门面(Facade)对象进行. 门面模式提供一个高层次 ...