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. [原创]VS2010中创建动态链接库及其调用

    [原创]VS2010中创建动态链接库及其调用 一.创建动态链接库 在VS2010中创建动态链接库的步骤如下: 1)生成->编译->生成MyDll 二.调用 当调用DLL中的方法,程序编译产 ...

  2. (原)测试intel的并行计算pafor

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/4988264.html 参考网址: 关于mt19937:http://www.cnblogs.com/e ...

  3. activiti笔记一:流程图xml文件

    一. 流程图有两个基本要素组成:点和线 点:开始节点.结束节点.各种网关.各种事件 线:连接两点之间的sequenceFlow 二. 一般包含三个步骤:部署.启动.完成 三. 启动的时候,可以设置流程 ...

  4. C语言做一个通讯录程序(在console里面运行)

    最近复习C语言的时候看到网上有个C语言通讯录的小项目,于是看了下那个程序实现的大概的功能,然后自己也跟着做了个.代码还算简洁,贴上来给有需要的人. // // main.m // AdressBook ...

  5. 深入 char * ,char ** ,char a[ ] ,char *a[] 内核

    本文来自CSDN博客:daiyutage的文章 来源网页地址:http://blog.csdn.net/daiyutage/article/details/8604720 本人觉得这是一编很有价值的文 ...

  6. Delphi线程同步(临界区、互斥、信号量,包括详细代码)

    当有多个线程的时候,经常需要去同步这些线程以访问同一个数据或资源. 例如,假设有一个程序,其中一个线程用于把文件读到内存,而另一个线程用于统计文件的字符数.当然,在整个文件调入内存之前,统计它的计数是 ...

  7. 线程初步了解 - <第一篇>

    操作系统通过线程对程序的执行进行管理,当操作系统运行一个程序的时候,首先,操作系统将为这个准备运行的程序分配一个进程,以管理这个程序所需要的各种资源.在这些资源之中,会包含一个称为主线程的线程数据结构 ...

  8. css案例学习之table tr th td ul li实现日历

    效果 代码 <html> <head> <title>Calendar</title> <style> <!-- .month { b ...

  9. Jump Game II 解答

    Question Given an array of non-negative integers, you are initially positioned at the first index of ...

  10. 转(havel 算法)

    http://www.cnblogs.com/wally/p/3281361.html poj 1659(havel算法) 题目链接:http://poj.org/problem?id=1659 思路 ...