Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
Sample Output

cat
eh
loops

大致题意:
输入一个字典,字典格式为“英语à外语”的一一映射关系
然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh”

输入时顺便用STL的map标记外语是否出现过,然后再用map建立“外语à英语”的映射,那么输出时先查找“出现”的标记,若有出现过,再输出映射,否则输出“eh”。

题解1:

 # include<iostream>
# include <cstdio>
# include<string>
# include<map>
using namespace std; int main(void)
{
char english[],foreign[]; map<string,string>translate; //记录foreign到engliash的映射 /*Input the dictionary*/ while(true)
{
char t; //temporary if((t=getchar())=='\n') //判定是否输入了空行
break;
else //输入english
{
english[]=t;
int i=;
while(true)
{
t=getchar();
if(t==' ')
{
english[i]='\0';
break;
}
else
english[i++]=t;
}
} cin>>foreign;
getchar(); //吃掉 输入foreign后的 回车符 translate[foreign]=english;
} /*Translate*/ char word[];
while(cin>>word)
{
if(translate.find(word) == translate.end()) //没找到
cout<<"eh"<<endl;
else
cout<<translate[word]<<endl;
} return ;
}

题解2:

 # include<iostream>
# include <cstdio>
# include<string>
# include<map>
using namespace std; int main(void)
{
char english[],foreign[]; map<string,bool>appear; //记录foreign与engliash的配对映射是否出现
map<string,string>translate; //记录foreign到engliash的映射 /*Input the dictionary*/ while(true)
{
char t; //temporary if((t=getchar())=='\n') //判定是否输入了空行
break;
else //输入english
{
english[]=t;
int i=;
while(true)
{
t=getchar();
if(t==' ')
{
english[i]='\0';
break;
}
else
english[i++]=t;
}
} cin>>foreign;
getchar(); //吃掉 输入foreign后的 回车符 appear[foreign]=true;
translate[foreign]=english;
} /*Translate*/ char word[];
while(cin>>word)
{
if(appear[word])
cout<<translate[word]<<endl;
else
cout<<"eh"<<endl;
} return ;
}

POJ 2503 单词映射(map)的更多相关文章

  1. poj 2503 Babelfish (查找 map)

    题目:http://poj.org/problem?id=2503 不知道为什么 poj  的 数据好像不是100000,跟周赛的不一样 2000MS的代码: #include <iostrea ...

  2. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  3. 题解报告:poj 2503 Babelfish(map)

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  4. poj 2503 哈希 Map 字典树

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36967   Accepted: 15749 Descr ...

  5. VIM键盘映射 (Map)~转载

    VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命令,可以通过F5键将单词用花括号括起来: :map <F5> i{e ...

  6. VIM键盘映射 (Map)

    http://www.pythonclub.org/linux/vim/map VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命 ...

  7. 图像映射map

    <map>标签:带有可点击区域的图像映射 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 效果图: 点击相应蓝色标签可进入详情页面浏览. 代码: < ...

  8. [51NOD1095] Anigram单词(map)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1095 字典的单词在map中排序和不排序各存1次,查的时候相减. ...

  9. <顶>vim快捷键映射Map使用

    问题描述: 使用vim中的快捷键映射map,可以自定义快捷键 问题解决: (1)vim模式 (2)map前缀 (3)删除映射Map (4)使用示例 (5)查看快捷键映射 命令行---:verbose ...

随机推荐

  1. Redis在Windows上使用和集群配置

    一.什么是Redis Redis是一个开源的,使用C语言编写的面向键值对类型的分布式Nosql数据库系统,功能类似Memcache,但比Memcache功能更丰富.官网地址:https://redis ...

  2. 推荐几个精致的web UI框架及常用前端UI框架

    1.Aliceui Aliceui是支付宝的样式解决方案,是一套精选的基于 spm 生态圈的样式模块集合,是 Arale 的子集,也是一套模块化的样式命名和组织规范,是写 CSS 的更好方式. git ...

  3. 转--python -- 收发邮件

    官方 import smtplib from email.mime.text import MIMEText from email.header import Header # 发送邮箱服务器 smt ...

  4. web4.0基本配置

    const path = require('path');//引入路径包 const HWP = require('html-webpack-plugin');//引入自动产出html包 const ...

  5. 2017CCPC秦皇岛 E题String of CCPC&&ZOJ3985【模拟】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3985 题意: 给定一个字符串,由c和p组成,可以添加c或者p. 串中出现一 ...

  6. C# 进程的挂起与恢复

    1. 源起: 仍然是模块化编程所引发的需求.产品经理难伺候,女产品经理更甚之~:p 纯属戏谑,技术方案与产品经理无关,芋头莫怪! VCU10项目重构,要求各功能模块以独立进程方式实现,比如:音视频转换 ...

  7. mysql 查询优化~join算法

    一简介:参考了几位师兄,尤其是M哥大神的博客,让我恍然大悟,赶紧记录下二 原理: mysql的三种算法 1 Simple Nested-Loop Join 将驱动表/外部表的结果集作为循环基础数据,然 ...

  8. Vim中自动在程序起始处添加版权和作者信息

    在编写程序的时候,经常需要在程序开始写上程序的简要介绍和作者信息,如下: 这种信息,除了文件名和修改时间可能经常发生变化外,其他基本不变,可以在程序开始自动加入,方法就是在家目录下的.vimrc中写入 ...

  9. SpringBoot处理静态资源的两种方式

    静态资源是指----> CSS.JS之类的文件 首先创建SpringBoot Web项目 添加Spring Boot Web Starter <dependency> <gro ...

  10. 【转】SSH服务详解

    [转]SSH服务详解 第1章 SSH服务 1.1 SSH服务协议说明 SSH 是 Secure Shell Protocol 的简写,由 IETF 网络工作小组(Network Working Gro ...