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. 把中文版NetBeans改成英文版

    不管你从官网下的是英文版还是中文版,安装之后操作界面都是中文的.这是因为NetBeans会根据你的操作系统自动设置界面语言,并且没有提供更改的功能.解决的方法也很简单,下面介绍我用过的两种方法: 方法 ...

  2. Android学习笔记之Service

    与服务通信 用bindservice 而startservice并无通信条件. service 为android为系统服务,所以程序员无法new出来,只能建立服务,共其他组件使用. package c ...

  3. 用 JS 点击左右按钮 使图片切换 - 最精简版-ljx2380000-ChinaUnix博客

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  4. 用css制作一个三角形箭头

    剑走偏锋——用css制作一个三角形箭头   通常,我们做上图那个三角形,一般都是做张图,而且需要两张,因为一般都是下拉菜单的效果,需要有个hover的样式,箭头是反的.那是不是有更好的办法呢,毕竟要用 ...

  5. java丢手帕 约瑟夫问题

    一.问题描述:     n个人围成一个圈,编号为1~n,从第一号开始报数,报到3的倍数的人离开,一直数下去,直到最后只有一个人,求此人编号. 二.问题提示:  使用一维数组,数组元素初始为1,从1开始 ...

  6. $.when().done().then()的用法

    jQuery的开发速度很快,几乎每半年一个大版本,每两个月一个小版本. 每个版本都会引入一些新功能.今天我想介绍的,就是从jQuery 1.5.0版本开始引入的一个新功能----deferred对象. ...

  7. jqGrid添加自定义按钮

    用法: <script> ... jQuery("#grid_id").navGrid("#pager",...).navButtonAdd(&qu ...

  8. HUST 1605 Gene recombination

    简单广搜.4进制对应的10进制数来表示这些状态,总共只有(4^12)种状态. #include<cstdio> #include<cstring> #include<cm ...

  9. nodejs抓取数据二(列表解析)

    这里做得比较暴力,没有分页取出数据解析,O(∩_∩)O哈哈~,居然没有被挂机.不过解析的坑特别多...不过大部分我想要的数据都拿到了. //解析列表数据 var http = require(&quo ...

  10. ajax 基础2

    连接数据库实现分页功能 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Defa ...