哈个希加挂个链表

一个要背的字符串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. js判断苹果安卓操作系统,js更换css

    //判断是哪个操作系统 if(plus.os.name=="Android"){ var lsyshowline=document.getElementById("lsy ...

  2. ACM-ICPC 2018 焦作赛区网络预赛 Give Candies 题解

    ACM-ICPC 2018 焦作赛区网络预赛 Give Candies n个糖果分给n个小朋友 从1到n个小朋友依次给,每次随机给个数,至少一个,知道没有糖果为止. 问糖果的分布情况方案数. 输出方案 ...

  3. 使用python 写一个 股票涨跌提醒功能

    1: 安装python: https://www.cnblogs.com/liyafei/articles/11550979.html 将python.exe加入 全局path 2: 安装库:(不需要 ...

  4. Wannafly Camp 2020 Day 6M 自闭 - 模拟

    按题意模拟,又乱又烦,没什么可说的 #include <bits/stdc++.h> using namespace std; #define int long long int n,m, ...

  5. P3391 【模板】文艺平衡树

    模板题 link Splay 区间翻转,存个代码 旋转时,要注意goal是引用 , 并记得修改 , 有标记的一定记得标记下放 , 还有清空 #include<iostream> #incl ...

  6. python:文件读写

    #!/usr/bin/python# -*- coding:utf-8 -*- #!/usr/bin/python# -*- coding:utf-8 -*- file1 = open('a.txt' ...

  7. Codeforces Round #600 (Div. 2) A. Single Push

    #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int T,n ...

  8. Linux 虚拟机共享目录

    1.  开启linux虚拟机 2.   菜单“虚拟机” -------“重新安装 Vm tools” 3.   桌面看到 VmTools 安装盘 4.   安装 5.   设置中添加共享目录 5.   ...

  9. js json -> <-object

    1.利用原生JSON对象,将对象转为字符串 var jsObj = {}; jsObj.testArray = [1,2,3,4,5]; jsObj.name = 'CSS3'; jsObj.date ...

  10. css+div上下左右自适应居中

    主要记录自己日常积累的布局相关的东西,持续更新中. 1.登录框上下左右自适应居中 以前想要把登录表单始终放置在页面的中间,花了不少心思,一直以来用的解决方法都是用js,感觉有点麻烦不是很好,于是在网上 ...