题目链接: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. bzoj 2850 巧克力王国 —— K-D树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2850 只要暴力判断是否全选一个子树或全不选,如果都不是就进入查询: 要注意值有负,所以不是直 ...

  2. python setuptools安装

    执行# python setup.py install 时发生如下错误 Traceback (most recent call last): File "setup.py", li ...

  3. category extension

    1 category 分类,只能添加方法,添加的方法成为原来类的一部分,达到扩展类的目的,可以被子类继承 主要给没有源代码的类 添加方法,团队合作项目互不影响,不该动原有类的基础上添加方法 self ...

  4. 【转】深刻理解render 和 redirect_to

    由于最近老是在表单提交后出现没有反应的现象,发现是在action中的使用render 和 redirect_to的原因,于是就想搞清楚他两真正的区别在哪里,上一遍的blog也谈到了这二者的区别,但是有 ...

  5. SpringMvc之参数绑定注解详解之二

    2 consumes.produces 示例 cousumes的样例: 1 @Controller   2 @RequestMapping(value = "/pets", met ...

  6. 问题:webservice浏览后 无法输入参数;结果:调试Web Service时不能输入参数的解决办法

    使用.NET 开发Web Service,有一个很方便的功能就是可以通过IE直接测试Web Service.当你的Web Service的参数都是元数据类型,那么只要你使用IE浏览Web Servic ...

  7. Ubuntu 切换root用户是时出现su Authentication failure

    su root 时出现错误su Authentication failure 原因是没有给root用户设置密码 sudo passwd root

  8. .clearfix:after

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

  9. Material使用10 MdRadioModule、MdDatepickerModule、MdNativeDateModule、MdSelectModule

    1 MdRadioModule 相当于<input type="radio"> 2 使用步骤 2.1 在共享模块导入MdRadioModule import { NgM ...

  10. layui 文件上传加进度条

    1.页面 <div class="layui-row layui-col-space5"> <div class="layui-form-item&qu ...