Babelfish

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 41263   Accepted: 17561

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

Hint

Huge input and output,scanf and printf are recommended.
 
思路:把字符串哈希成26进制数,然后查找的复杂度就是线性的。字符串共有26^10种可能,约等于10^14,可以用long long存下。使用map,key为哈希值,value为该串的位置。
 //2016.9.4
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#define N 100005 using namespace std; char s1[N][], s2[N][], str[];
map<long long, int> Hash; long long F(char* s)//把字符串hash成一个26进制数
{
int len = strlen(s);
long long h = ;
for(int i = ; i < len; i++)
h = h*+(s[i]-'a');
return h;
} int main()
{
int cnt = ;
while(gets(str))
{
if(str[] == '\0')break;
sscanf(str,"%s%s", s1[cnt], s2[cnt]);
long long h = F(s2[cnt]);
Hash[h] = cnt;
cnt++;
}
while(gets(str))
{
if(str[] == '\0')break;
long long h = F(str);
if(Hash.find(h)!=Hash.end())//map按key查找,失败返回end
printf("%s\n", s1[Hash[h]]);
else printf("eh\n");
} return ;
}

POJ2503(hash)的更多相关文章

  1. POJ-2503 Babelfish---map或者hash

    题目链接: https://vjudge.net/problem/POJ-2503 题目大意: 就像查找一本字典,根据输入的条目和要查询的单词,给出查询结果(每个单词长度不超过10) 解题思路: ma ...

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

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

  3. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  4. 对抗密码破解 —— Web 前端慢 Hash

    (更新:https://www.cnblogs.com/index-html/p/frontend_kdf.html ) 0x00 前言 天下武功,唯快不破.但在密码学中则不同.算法越快,越容易破. ...

  5. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  6. hash表长度优化证明

    hash表冲突的解决方法一般有两个方向: 一个是倾向于空间换时间,使用向量加链表可以最大程度的在节省空间的前提下解决冲突. 另外一个倾向于时间换空间,下面是关于这种思路的一种合适表长度的证明过程: 这 ...

  7. SQL Server-聚焦查询计划Stream Aggregate VS Hash Match Aggregate(二十)

    前言 之前系列中在查询计划中一直出现Stream Aggregate,当时也只是做了基本了解,对于查询计划中出现的操作,我们都需要去详细研究下,只有这样才能对查询计划执行的每一步操作都了如指掌,所以才 ...

  8. C# salt+hash 加密

    一.先明确几个基本概念 1.伪随机数:pseudo-random number generators ,简称为:PRNGs,是计算机利用一定的算法来产生的.伪随机数并不是假随机 数,这里的" ...

  9. SQL 提示介绍 hash/merge/concat union

    查询提示一直是个很有争议的东西,因为他影响了sql server 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...

随机推荐

  1. ASer Python学习笔记

    最近又开始学习python了,希望自己能坚持下去. 我看的书是thinkingpython,是在豆瓣的python学习组看到的. 连续看了3,4天左右,然后尝试着写了个小程序,复制文件的,代码如下: ...

  2. CDOJ 1271 Search gold

    简单DP.dp[i][j]表示走到这格的最大金钱数. #include<cstdio> #include<cstring> #include<cmath> #inc ...

  3. python字符串,列表,字典的常用方法

    本篇内容 字符串的常用方法 列表的常用方法 字典的常用方法 字符串的常用方法 center 字符居中显示,指定字符串长度,填充指定的填充字符 string = "40kuai" p ...

  4. zookeoper在root下设置开机启动

    1 准备工作 1) 切换到/etc/rc.d/init.d/目录下 2) 创建zookeeper文件:touch zookeeper 3)更新权限:chmod +777 zookeeper 4)编辑文 ...

  5. awk简单用法

    awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各 ...

  6. laravel项目安装debugbar

    在github上有laravel项目的debugbar,可以查看项目的页面引用.变量.数据库使用.内存和反应时间等,貌似是一个还不错的小工具,效果如下: 安装地址:https://github.com ...

  7. 微信小程序初体验--封装http请求

    最近看了一下微信小程序,大致翻了一下,发现跟angular很相似的,但是比angular简单的很多具体可参考官方文档 https://mp.weixin.qq.com/debug/wxadoc/dev ...

  8. IOS开发-UI学习-UITextField的各种属性设置

    UITextField是IOS中非常常用的一个控件,用来接收用户输入信息,完成应用和用户的交互.它的主要属性设置如下: //初始化textfield并设置位置及大小 UITextField *text ...

  9. IOS开发-OC学习-NSTimer的使用

    上一篇博客中在改变属性值的时候使用了timer进行自动改变.关于NSTimer的更详细的用法如下: 定义一个NSTimer类型的timer,和一个count,其中timer是定时器,count是计数的 ...

  10. Apache 代理(Proxy) 转发请求

    代理分为:正向代理(Foward Proxy)和反向代理(Reverse Proxy) 1.正向代理(Foward Proxy) 正向代理(Foward Proxy)用于代理内部网络对Internet ...