题目链接: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 oopslayatcay
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[15],s2[15];map<string,bool>appear;//刚开始默认为falsemap<string,string>translate;while(1){char t;if((t=getchar())=='\n')break;else{s1[0]=t;int i=1;while(1){t=getchar();if(t==' '){s1[i]='\0';break;}elses1[i++]=t;}}cin>>s2;getchar();appear[s2]=true;translate[s2]=s1;}char word[15];while(cin>>word){if(appear[word])cout<<translate[word]<<endl;elsecout<<"eh"<<endl;}return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/9400990.html

Babelfish (关于mapstring,string的用法相关推荐

  1. substring java_Java String.substring()用法

    首页 > 基础教程 > 常用类 > 常用 String类 Java String.substring()用法 substring() 方法返回字符串的子字符串. 语法 public ...

  2. STL中map和string, vector 用法详解

    1. map 用法详解 std map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成 ...

  3. 用std::string::compare()用法

    c++系列文章目录 c++处理文本相对于python等脚本语言还是挺麻烦的,往往需要和fstream.fstream.string.一起配合使用才能完全把文本解析出来.其实,string并不是一个单独 ...

  4. C++中std::string::find_last_of用法

    早上本来还看代码时本来还迷迷糊糊,结果被find_last_of一下给震醒了,std::string 使用了这么多年,今天才发现find_last_of只是用来查找字符的,多年来一直以为它可用来查找字 ...

  5. 【贪玩巴斯】带你学:C++ tips ——知识点:string::npos 用法详细解析 , 看这一篇就够了 2021年12月21日

    [贪玩巴斯]带你学:C++ tips --知识点:string::npos 用法详细解析 !!! 一.定义 二.使用 1.如果作为一个返回值(return value)表示没有找到匹配项 2.但是st ...

  6. 最大质因数 最大回文数乘积 字符串String类用法_Java每日练习题及题解(11月16日)

    <Java每日练习题及题解>系列目录 1.有限条件求和_Java每日练习题及题解(11月15日) 2.最大质因数 最大回文数乘积 字符串String类用法_Java每日练习题及题解(11月 ...

  7. string 基本用法

    膜拜大佬orz  http://www.cnblogs.com/OIerShawnZhou/ 最基本的,头文件 #include <cstring> #include <string ...

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

    2019独角兽企业重金招聘Python工程师标准>>> 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好 ...

  9. c++ string类 用法简介

    目录 1. 概述 2. 常见用法 2.1 string转换为char* 2.1.1 data()方法与c_str()方法 2.2 计算string长度.string字符串比较 2.3 string对象 ...

最新文章

  1. java 实现set_js 实现JAVASET
  2. 计算机用于尖端科技,【判断题】用演绎法教问句的方法适用于中高级型学生
  3. python版本升级和系统更新下载安装_Python环境安装与升级
  4. 双列集合Map的实现类
  5. 前端学习(3206):初始化state
  6. Madagascar的自定义浮点型函数--指数函数和幂函数
  7. Java构造字符串算法题_LeetCode算法题-Repeated Substring Pattern(Java实现)
  8. 阿里云图数据库GDB公测,高度连接数据查询效率提升10倍
  9. sql mdf文件被破坏,ldf完好的情况下恢复数据库
  10. 【BZOJ 3531 Sdoi2014】旅行【动态开点线段树+树链剖分】
  11. linux HUSTOJ 一些页面修改
  12. 连载31:软件体系设计新方向:数学抽象、设计模式、系统架构与方案设计(简化版)(袁晓河著)...
  13. minicom 下载
  14. Android接入谷歌广告 - 发现各种坑
  15. 4G无线WIFI太阳能低功耗监控摄像头野外4G监控无电无网远程摄像机
  16. pymysql.err.OperationalError: (1130, “xxx‘ is not allowed to connect to this MySQL server“)
  17. 波兰式和逆波兰的相互转化
  18. ul、li中的DIV垂直居中
  19. 外贸管理软件是怎样帮您管理客户的?
  20. 每周一品 · 永磁联轴器 Magnetic Couplings

热门文章

  1. 你在成长为一个优秀的程序员吗
  2. IMP-00009: 导出文件异常结束 imp
  3. 【干货】神策标签生产引擎架构
  4. 推荐算法工程师必备!!!协同过滤推荐算法总结
  5. 一文速览!多模态预训练中的 Prompt 范式
  6. LambdaLoss | Google排序学习优化框架
  7. html怎么加漂浮物,全面开展水面漂浮物清理专项行动
  8. mysql交叉组合查询,MySQL数据透视/交叉表查询
  9. Leetcode每日一题:56. I. 数组中数字出现的次数
  10. Java-Collection、List