题目链接: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. MYSQL主从复制配置遇到的问题

    在进行配置从服务器时遇到的错误. mysql> change master to master_host='192.168.136.129',master_user='repl',master_ ...

  2. vijos1779国王游戏

    描述 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排成一排,国王站在队伍的最前面.排好队后, ...

  3. shock编程

    Socket接口是TCP/IP网络的API,Socket接口定义了许多函数或例程,程序员可以用它们来开发TCP/IP网络上的应用程序.要学Internet上的TCP/IP网络编程,必须理解Socket ...

  4. tomcat如何修改发布目录

    tomcat免重启 tomcat访问的时候如何去掉项目名访问: 其中fts是您的项目名. 1.tomcat6.0:<Host></Host>间加了一句<Context p ...

  5. HTTP 2 VS HTTP 1.1

    提升H5应用加载速度的方式有很多,比如缓存.cdn加速.代码压缩合并和图片压缩等技术. 今天介绍的是HTTP 2.0

  6. VMware Workstation虚拟机安装Windows 7系统

    1.进入VMware Workstation虚拟机软件界面,选择新建虚拟机

  7. linux命令-vim编辑模式

    按  i  键 进去编辑模式 左下角显示 插入 按 I  键 进入编辑模式 光标到行首 按 a 键 在光标的后一位 按A 键 光标在行尾 按 o 键 在光标下面另起一行 按O 键  在光标上面另起一行 ...

  8. Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute

    ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...

  9. Android 设计模式情景分析——观察者模式

    观察者模式是一种使用频率非常高的模式,有时也被称作发布/订阅模式,属于行为型模式,它最常用的是 GUI 系统.订阅——发布系统,它一个重要作用就是解耦,使得它们之间的依赖性更小.观察者模式定义了对象间 ...

  10. Python:列表也能拆包?

    前几天,微信学习群里有个小伙伴在看书时遇到了这样一个问题,在群里提问,看下图: 这是常用的 matplotlib 库,只是一般我们调用 plot 方法绘图时,不会去关心它的返回值.然而 plt1, = ...