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. jQuery实现滚动监听

    1.设计思路 1)获取窗口滚动高度: 2)获取附加导航栏: 3)获取导航栏下的所有li: 4)通过相同class获取所有监听元素:(此例中为jumbotron巨幕) 5)遍历所有监听元素,若当前元素距 ...

  2. Java编程思想 学习笔记1

    一.对象导论 1.抽象过程 Alan Kay曾经总结了第一个成功的面向对象语言.同时也是Java所基于的语言之一的Smalltalk的五个基本特性,这些特性表现了纯粹的面向对象程序设计方式 1)万物皆 ...

  3. db.properties文件的配置格式

    #加载驱动 mysql.driver=com.mysql.jdbc.Driver #加载数据库 mysql.url=jdbc:mysql://localhost:3306/floor_shop #用户 ...

  4. Json Schema简介

    1. 引言 什么是Json Schema? 以一个例子来说明 假设有一个web api,接受一个json请求,返回某个用户在某个城市关系最近的若干个好友.一个请求的例子如下: { "city ...

  5. luogu P2596 [ZJOI2006]书架

    传送门 感觉要死在\(Splay\)里了 orz 这题用\(Splay\)维护这个序列,其中的第\(k\)大点代表这个序列的第\(k\)个数 第一个操作,先把那个数所在的点旋到根,然后把整个根的左子树 ...

  6. mysql数据库备份和恢复

    1.数据库备份 mysqldump -uroot -proot jira736 > jira736.sql 2.数据库恢复 mysql -uroot -proot jira762 < ji ...

  7. python3中的比较函数

    在py2中,比较函数是cmp,而在py3,cmp已经不存在了,Py3启用了新的比较方法 原来在py2中,a>b就会调用a对象中的__cmp__函数,而现在a>b会调用a对象中的__lt__ ...

  8. mongodb系列~mongo常用命令

    mongodb常用命令大全1 索引相关命令 db.chenfeng.ensureIndex({"riqi":1}) 添加索引会阻塞nohup mongo --eval " ...

  9. kset学习demo以及Oops反汇编objdump调试例子【原创】

    写一个main.c gcc -c -g main.c objdump -S main.o > b.txt arm-none-linux-gnueabi-gcc -c -g a.c arm-non ...

  10. GHOST分区丢失只剩C盘

    很多人装系统时会经常会使用GHOST来恢复自己的系统,当WINDOWS系统出现意外时,再用GHOST的“From Image to 分区”来对系统进行恢复,这样就可以省去繁琐耗时的重新安装操作系统的工 ...