题目链接:https://vjudge.net/contest/237395#problem/A

学习博客:https://blog.csdn.net/lyy289065406/article/details/6647413

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay

Sample Output

cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.
题目大意:每行输入两个字符串,前面的是Englih,后面的是字典里的前面那个的翻译,当遇到空行接着输入的是要你查找的单词,如果找到了输出对应的English,没找到则输出eh
个人思路:第一眼看到就觉得是用map来做,因为map可以存任意类型的变量,而且是一对一的关系,这就非常符合了,但是这题的输入有点麻烦,具体看代码
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<map>
using namespace std;
int main()
{
char s1[],s2[];
map<string,bool>appear;//刚开始默认为false
map<string,string>translate;
while()
{
char t;
if((t=getchar())=='\n')
break;
else
{
s1[]=t;
int i=;
while()
{
t=getchar();
if(t==' ')
{
s1[i]='\0';
break;
}
else
s1[i++]=t;
}
}
cin>>s2;
getchar();
appear[s2]=true;
translate[s2]=s1;
}
char word[];
while(cin>>word)
{
if(appear[word])
cout<<translate[word]<<endl;
else
cout<<"eh"<<endl;
}
return ;
}

Babelfish (关于map<string,string>的用法的更多相关文章

  1. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  2. 入门:Java Map<String,String>遍历及修改

    重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...

  3. alibaba fastjson List<Map<String, String>>2Str

    import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; impo ...

  4. getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

    直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...

  5. 标准C++中的string类的用法总结

    标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...

  6. JAVA/Android Map与String的转换方法

    在Android开发中 Map与String的转换在,在一些需求中经常用到,使用net.sf.json.JSONObject.fromObject可以方便的将string转为Map.但需要导入jar包 ...

  7. FastJSON 简介及其Map/JSON/String 互转

    在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个 ...

  8. 使用STL map 用 string 做索引 插入删除数据

    1.代码 #include <map> #include <string> #include <stdio.h> #include <vector> # ...

  9. JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类

    <pre name="code" class="java"></pre><pre name="code" cl ...

随机推荐

  1. Poj_1008--Maya Calendar

    一.Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现.从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法.这个Haab ...

  2. 第 六 课 GO语言常量

    http://www.runoob.com/go/go-constants.html 一 常量 是一个简单值的标识符,在程序运行时,不会被修改的量. 常量中的数据类型只可以是布尔型.数字型(整数型.浮 ...

  3. JS---改变图片大小

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. MyBatis总结(1)

    MyBatis前身是ibatis,是一个数据持久层框架.封装优化了普通JDBC过程, 如数据库连接的创建.设置SQL语句参数.执行SQL语句.事务.结果映射以及资源释放等. MyBatis是一个支持普 ...

  5. js---复选框(全选,不选,反选)demo1--

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  6. [matlab]机器学习及SVM工具箱学习笔记

    机器学习与神经网络的关系: 机器学习是目的,神经网络是算法.神经网络是实现机器学习的一种方法,平行于SVM. 常用的两种工具:svm tool.libsvm SVM分为SVC和SVR,svc是专门用来 ...

  7. 6.5 Ubuntu中安装搜狗输入法

    传统的方式:http://www.cnblogs.com/zlslch/p/6943318.html 最简单的方式:

  8. redis系列:通过队列案例学习list命令

    前言 这一篇文章将讲述Redis中的list类型命令,同样也是通过demo来讲述,其他部分这里就不在赘述了. 项目Github地址:https://github.com/rainbowda/learn ...

  9. java 多线程学习笔记(一) -- 计算密集型任务

    最近在看<Java虚拟机并发编程>,在此记录一些重要的东东. 线程数的确定:1. 获取系统可用的处理器核心数:int numOfCores = Runtime.getRuntime().a ...

  10. Maven的相关知识及使用

    一.简介 maven: 是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的,Maven是跨平台的项目管理工具. 1.自动化构建和项目管理工具 Ant→Make→Maven ...