poj2503 哈希表
来源:互联网 发布:淘宝新手怎样增加粉丝 编辑:程序博客网 时间:2024/04/28 12:09
如题: http://poj.org/problem?id=2503
一行输入2个字符串,第一个是一种语言表示,第二个是另一种语言表示,但他们的意思相同,只是表达不同。建完字典后,输入第2种语言的单词,输出第一种语言的表示方法。如果没有这个单词,输出eh
用ELFhash表做,使用开放散列。
ELFhash表具体解释,见我上一篇。
#include<iostream>
#include<cstring>
//#define MOD 0x7fffffff
#define M 100003
int ELFHash(char * key)
{
unsigned long h=0;
while(*key)
{
h=(h<<4)+*key++;
unsigned long g=h&0xf0000000L;
if(g)
{
h^=(g>>24);
h&=~g;
}
}
return h%M;
}
struct node
{
int hash;
struct node * next;
}* Link[M]={NULL};
char word[M][11];
char dialect[M][11];
int main()
{
int i,e,n=0;
char str[50];
struct node * p;
gets(str);
while(strcmp(str,"")!=0)
{
for(i=0;str[i]!=' ';i++)
{
word[n][i]=str[i];
}
word[n][i++]='\0';
strcpy(dialect[n],str+i);
e=ELFHash(dialect[n]);
p=new node();
p->hash=n;
p->next=Link[e];
Link[e]=p; //防止冲突
n++;
gets(str);
}
while(gets(str)!=NULL)
{
e=ELFHash(str);
p=Link[e];
while(p!=NULL)
{
if(strcmp(str,dialect[p->hash])==0)
{
break;
}
p=p->next;
}
if(p==NULL)
printf("eh\n");
else
printf("%s\n",word[p->hash]);
}
return 0;
}
- poj2503 哈希表
- POJ2503
- poj2503
- poj2503
- POJ2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- poj2503
- POJ2503
- poj2503 hash
- VS中多项目联合开发技巧
- 第12周项目2(3)-刑警的射击成绩
- C++虚基类详解
- 最小公共祖先(LCA)离线算法_Tarjan c++实现
- 【贪心】【SGU 410】 Galaxy in danger
- poj2503 哈希表
- [数据结构]线段树
- 字符型减'0'可以得到整数型”的原因分析
- zTree之checkbox选中事件---获取状态改变的结点
- C语言--------逗号表达式分析一:
- HDOJ 4745 Two Rabbits DP
- 分页计算总页数算法
- 编程:含有全局变量的程序阅读(1)
- 二叉树sdutoj1303