poj2503
有关字符串的hash,用黑书上推荐的传说中的ELFhash函数
输入的话,用sscanf处理比較简洁
#include<iostream>
#include<cstring>
using namespace std;
#define M 9991
struct n1
{
char foreigh[11],english[11];
n1 *next;
};
n1 hash[M];
int ELFhash(char *key)
{
long long g,h=0;
while(*key)
{
h=(h<<4)+*key++;
g=h&0xf0000000L;
if(g)
h^=g>>24;
h&=~g;
}
return h%M;
}
void find(char *s)
{
n1 *p;
for(p=&hash[ELFhash(s)];p->next!=0;p=p->next)
if(strcmp(p->foreigh,s)==0)
{
printf("%s\n",p->english);
return;
}
printf("eh\n");
}
void insert(char *e,char *f)
{
n1 *p;
for(p=&hash[ELFhash(f)];p->next!=0;p=p->next);
strcpy(p->english,e);
strcpy(p->foreigh,f);
p->next=new(n1);
p->next->next=0;
}
void datain()
{
char tmp[22],english[11],foreigh[11];
while(gets(tmp)&&tmp[0])
{
sscanf(tmp,"%s %s",english,foreigh);
insert(english,foreigh);
}
}
void solve()
{
char foreigh[11];
memset(hash,0,sizeof(hash));
datain();
while(scanf("%s",foreigh)!=EOF)
find(foreigh);
}
int main()
{
solve();
}
poj2503的更多相关文章
- POJ2503——Babelfish(map映射+string字符串)
Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...
- POJ-2503 Babelfish---map或者hash
题目链接: https://vjudge.net/problem/POJ-2503 题目大意: 就像查找一本字典,根据输入的条目和要查询的单词,给出查询结果(每个单词长度不超过10) 解题思路: ma ...
- POJ2503字典树
此代码原始出处:http://blog.csdn.net/cnyali/article/details/47367403 #include<stdio.h> #include<str ...
- POJ2503 Babelfish map或者hash_map
POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...
- poj2503 哈希
这题目主要是难在字符串处理这块. #include <stdio.h> #include <string.h> #include <stdlib.h> #defin ...
- POJ2503——Babelfish
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- POJ2503 Babelfish
题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...
- POJ2503(hash)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41263 Accepted: 17561 Descr ...
- 2017ecjtu-summer training #2 POJ2503
...
随机推荐
- instsrv.exe下载和使用方法(微软Windows Server 2003 Resource Kit Tools工具中的一个)
instsrv.exe是微软Windows Server 2003 Resource Kit Tools工具中的一个. Windows Server 2003 Resource Kit Tools是一 ...
- Baidu Sitemap Generator插件使用图解教程
这两天因为百度对本博客文章收录更新很慢,一直在网络查找真正的原因和解决方法.最终发现了柳城开发的Baidu Sitemap Generator WordPress插件,最终效果如果还需要验证一段时间. ...
- Life is short, you need Python
今年四五月份的时候我打算学一门计算机语言. 计算机语言实在是很多,选哪一个? 其实这个选择就和去市场买菜类似,想明白了自己的需求才能做好决定.你想做什么饭,就去买什么菜.想做南瓜粥,就要去买南瓜,想要 ...
- TestWriter自动化测试介绍
简介: TestWriter是上海博为峰结合多年为企业做测试服务的经验所研发的一款具有自主知识产权的自动化测试工具,为企业用户提供真正的低成本.高效率的自动化测试,引领软件测试自动化运用由技术层面向业 ...
- 彩虹vpn免费10分钟
账号:rainbowvpn password:10fenzhong server地址:t.chqvpn.com l2tp密钥:123456
- ubuntu高版本环境变量问题
在ubuntu较高的版本(博主使用的是14.10)下,可以在/etc/environment中配置环境变量,这个环境变量可能会覆盖用户~/.bashrc中配置的环境变量,这个应该引起注意.
- 《JavaScript 闯关记》之初探
当学习一门新的编程语言的时候,应该边学边做,反复演练以加深理解.因此,你需要一个 JavaScript 解释器.幸运的是,每一个 Web 浏览器都包含一个 JavaScript 解释器. 可以通过在 ...
- C# 中的委托和事件详解
C# 中的委托和事件 文中代码在VS2005下通过,由于VS2003(.Net Framework 1.1)不支持隐式的委托变量,所以如果在一个接受委托类型的位置直接赋予方法名,在VS2003下会报错 ...
- Android EditText小结
防止EditText获取焦点弹出输入法 android:focusable="true" android:focusableInTouchMode="true" ...
- HTML6注册表单输入日志标题
一.找到元素. var d = document.getElementById("") var d = document.getElementsByName("" ...