哈个希加挂个链表

一个要背的字符串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. PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)

    Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...

  2. Codeforces Round #622 (Div. 2) C2 - Skyscrapers (hard version) 单调栈

    从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long ...

  3. 使用FDATOOL生成xilinx中FIR滤波器IP核的系数

    1.在MATLAB命令窗口输入fdatool后回车,打开“Filter Designer & Analysis Tool”工具界面: 2.点击左下角的Set quantization para ...

  4. 基于Dapper的开源Lambda扩展LnskyDB 3.0已支持Mysql数据库

    LnskyDB LnskyDB是基于Dapper的Lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以T4生成实体类免去手写实体类的烦恼.,现在已经支持MySql和Sql serv ...

  5. 2019-08-18 纪中NOIP模拟A组

    T1 [JZOJ6309] 完全背包 题目描述

  6. Quick Sort(快速排序)

    Quick Sort Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a ...

  7. 曼孚科技:AI自然语言处理(NLP)领域常用的16个术语

    ​自然语言处理(NLP)是人工智能领域一个十分重要的研究方向.NLP研究的是实现人与计算机之间用自然语言进行有效沟通的各种理论与方法. 本文整理了NLP领域常用的16个术语,希望可以帮助大家更好地理解 ...

  8. 18新生赛 4. Deal

    题目描述:双十一过后,syx发现自己快要吃土了.但是机智的他决定理财.他预测了将来n天的比特币行情,发现有涨有跌,有跌有涨.手里的钱只要在比特币的浪潮中经历沉浮,低价收入,高价卖出,就可以轻易割到别人 ...

  9. badge徽章、挂件模版

    markdown语法 Gitee卡片 Gitee挂件 Github挂件 Gitee卡片 [![gqzdev/ForFuture Group](https://gitee.com/zhong96/sho ...

  10. Java基本语法--控制台输入(Scanner类)

    通过Scanner类获取用户输入时,控制台会一直等待用户的输入,可以输入不同类型的值.本篇博客主要讲解从控制台输入值,即Scanner类的使用方法. Api文档中关于Scanner类的构造方法 键盘输 ...