Description

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
解题思路:查字典--->map键值对,由于时间限制,要用C语言的输入输出,因此输入时考虑用sscanf函数来格式化读取的字符串,其他常规处理即可。
int sscanf (const char *str,const char * format,........);
sscanf函数会将参数str字符串根据参数format字符串来转换并格式化数据,转换后的结果存于对应的参数内。返回值:如果成功,该函数返回成功匹配和赋值的个数。如果到达文件末尾或发生读错误,则返回EOF。
AC代码(2157ms):
 #include<iostream>
#include<map>
#include<string.h>
#include<cstdio>
using namespace std;
const int maxn=;
char str[maxn],obj[maxn],ans[maxn];
map<string,string> mp;
int main(){
while(gets(str)&&strlen(str)){
sscanf(str,"%s%s",ans,obj);//格式字符串
mp[obj]=ans;//映射(字典)
}
while(gets(str)){
if(mp.find(str)!=mp.end())printf("%s\n",mp[str].c_str());
else printf("eh\n");
}
return ;
}

题解报告:poj 2503 Babelfish(map)的更多相关文章

  1. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  2. Poj 2503 Babelfish(Map操作)

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

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

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

  4. poj 2503 Babelfish (查找 map)

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

  5. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

  6. poj 2503 Babelfish(字典树或着STL)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35828   Accepted: 15320 Descr ...

  7. poj 2503:Babelfish(字典树,经典题,字典翻译)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Descr ...

  8. POJ 2503 Babelfish

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28766 Accepted: 12407 Descripti ...

  9. POJ 2503 Babelfish (STL)

    题目链接 Description You have just moved from Waterloo to a big city. The people here speak an incompreh ...

随机推荐

  1. Office EXCEL 中单元格怎么打斜线

    右击单元格,然后设置单元格格式,然后添加需要的边框     注意里面的文字有讲究,比如我要右上角显示Value,左下角显示Payload,则需要先输一堆空格,然后输入Value,把Value挤到右边去 ...

  2. 微信小程序-setData()方法

    一般setData方法多用于点击后改变页面信息或者刷新后与后台交互获取最新的信息 注意: 直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致 ...

  3. MySql 基本操作语句整理

    数据库 DATABASE: 创建 CREATTE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [DEFAULT] CHARACTER SET [=] cha ...

  4. js 判断对象中所有属性是否为空

    测试: var obj = {a:"123",b:""}; for(var key in obj){ if(!obj[key]) return; } 函数封装: ...

  5. 论持久战之PHPStorm Xdebug Remote 调试环境搭建(不依赖本地环境)

    最近公司自己搭建了一个资源管理平台,哈哈,当然是我在github上找的,后台用PHP开发.个人觉得写得非常nice,web页面几乎模拟了真实OS,有兴趣的朋友下载部署体验https://github. ...

  6. ubuntu hadoop伪分布式部署

    环境 ubuntu hadoop2.8.1 java1.8 1.配置java1.8 2.配置ssh免密登录 3.hadoop配置 环境变量 配置hadoop环境文件hadoop-env.sh core ...

  7. 关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料

    关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&quo ...

  8. linux epoll的实现原理

    1 linux的poll操作 linux文件的poll操作有两个主要目的:第一,主动查看该文件上是否有读写事件:第二,提供操作waitqueue的接口给epoll等上层接口使用,比如epoll可以通过 ...

  9. XMU 1605 nc与数列 【动态规划】

    1605: nc与数列 Time Limit: 2000 MS  Memory Limit: 64 MBSubmit: 84  Solved: 13[Submit][Status][Web Board ...

  10. java垃圾回收机制的使用

    public class Test { public static void main(String[] args) throws Exception { Book b=new Book(true); ...