哈个希加挂个链表

一个要背的字符串hash函数ELFhash()

mod数取数据最大容量的1.5倍最佳?!

 #include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;//比1e5大的质数
struct node{char e[],f[];int next;}word[MAXN];
int cnt,hashHead[MAXN];char s[]; int ELFhash(char *key){
unsigned long h=;
for(unsigned long g;*key;h&=~g){
h=(h<<)+(*key++);
g=h&0Xf0000000L;
if(g)h^=g>>;
}
return h%MAXN;
} void find(){
int hash=ELFhash(s);
for(int i=hashHead[hash];i;i=word[i].next)
if(strcmp(s,word[i].f)==)
{printf("%s\n",word[i].e);return;}
printf("eh\n");
} int main() {
for(cnt=;gets(s)&&s[]!='\0';cnt++/*cnt++必须写在外面*/) {
sscanf(s,"%s%s",word[cnt].e,word[cnt].f);
int hash = ELFhash(word[cnt].f);
word[cnt].next=hashHead[hash];//挂表
hashHead[hash]=cnt;
}
while(gets(s))find();
return ;
}

C++-POJ2503-Babelfish[hash]的更多相关文章

  1. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  2. POJ2503 Babelfish map或者hash_map

    POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...

  3. POJ2503(Babelfish)--简单字典树

    思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...

  4. POJ2503——Babelfish

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

  5. POJ2503 Babelfish

    题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...

  6. poj_2503(map映射)

    题目链接poj2503 Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38820   Accepted: ...

  7. POJ2503(hash)

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

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

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

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

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

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

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

随机推荐

  1. openlayers按坐标点播放

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Django-模型(二)

    条件查询 字段查询 实现sql中where的功能,调用过滤器filter().exclude().get(),下面以filter()为例. 通过"属性名_id"表示外键对应对象的i ...

  3. windows命令提示符常用命令

    1.进入某个磁盘 c:  进入c盘 d: 进入d盘 2.返回到根目录 cd \ 3.查看当钱路径下的文件和文件夹 dir 4.清空窗口内容 cls 5.关闭窗口 exit 6.返回上一级目录 cd . ...

  4. CF571D Campus(19-1)

    题意 \(n\)个点,维护两个森林,这里\(A,B\)两个森林对应的点都是一样的,相当于对两个森林操作都会影响这\(n\)个点 开始森林里的树都是一个点,\(A,B\)支持合并(但树结构互不影响),\ ...

  5. laravel框架用使用session 和cookie

    1.介绍 cookie 位于用户的计算机上,用来维护用户计算机中的信息,直到用户删除.比如我们在网页上登录某个软件时输入用户名及密码时如果保存为cookie,则每次我们访问的时候就不需要登录网站了.我 ...

  6. LaTeX技巧003:实现一个章标题

    代码如下: \documentclass[11pt]{book} \usepackage{graphicx} \usepackage{CJKfntef} \usepackage{color} \mak ...

  7. Codeforce 230A - Dragons (sort)

    Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defe ...

  8. H3C链路聚合

    以太网链路聚合通过将多条以太网物理链路捆绑在一起形成一条以太网逻辑链路,实现增加链路带宽的目的,同时这些捆绑在一起的链路通过相互动态备份,可以有效地提高链路的可靠性. 一.基本概念 1.聚合接口/聚合 ...

  9. java的开发步骤----

    首先老师给了一个 视频给我:叫我理解java的简单开发步骤: 上两张图: 然后我就理解成了这样::: 简述java开发步骤:第一步: 编写源代码,把源代码写好 :第二部:源代码通过编译器编译成字节码c ...

  10. MongoDB的安装问题

    Mongo的安装与启动: npm install mongodb -g MongoDB高性能.开源.无模式的文档型数据库,它基于分布式文件存储.介于关系数据库和非关系数据库之间的一种产品.其最大特点: ...