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. FTRL (Follow-the-regularized-Leader)算法

    Online gradient descent(OGD) produces excellent prediction accuracy with a minimum of computing reso ...

  2. Bound mismatch: The typae CertificateDirectory is not a valid substitute for the bounded parameter <M extends Serializable>

    这是因为架包没导对或者关联的项目不是在同一个工作空间.

  3. [RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS

    When subscribers create new "inner" sources and subscriptions, you run the risk of losing ...

  4. Javascript 运行机制

    先看一下下面这段js代码: console.log('1'); setTimeout(function(){ console.log('2'); },0); console.log('3'); 请问打 ...

  5. 初识mina框架

    step1:创建java工程,导入jar包 step2:在src下配置log4j.properties文件 log4j.rootLogger=DEBUG,MINA,file log4j.appende ...

  6. 大型网站技术架构(四)--核心架构要素 开启mac上印象笔记的代码块 大型网站技术架构(三)--架构模式 JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    大型网站技术架构(四)--核心架构要素   作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载.此篇已收录至<大型网站技 ...

  7. cocos2d-x CCSrollView 源代码,可循环的SrollView代码

    项目须要.写一个类似于iPhone上面时钟选择的可拉动式循环选择列表,通过集成CCScrollView并更改部分代码.实现了该功能. 假设想充分了解代码,请先阅读源码分析http://blog.csd ...

  8. WPF 创建二维码

    1.在http://zxingnet.codeplex.com/网站上下载ZXing .Net的第三方库 2.新建一个WPFproject 3.引入zxing.dll 4.加入引用空间 using Z ...

  9. win64 qt与fortran (codeblocks) 混合编程

    本教程主要解说用fortran生成dll供qt调用(win64) 本教程须要的软件及文件可从以下的连接下载: http://pan.baidu.com/s/1c04jziC fortran我用的软件是 ...

  10. (八)Java 修饰符

    Java 修饰符 Java语言提供了很多修饰符,主要分为以下两类: 访问修饰符 非访问修饰符 修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class ...