#include<stdio.h>
#include<string.h>
const int MAX_ENTRY=100000;
const int Max_WORD_LEN=12;
const int MAX_HASH_SIZE=21169;
struct Entry{
char english[Max_WORD_LEN];
char foreign[Max_WORD_LEN];
};
struct LNode{
int ind;
LNode* next;
};
Entry dict[MAX_ENTRY];
LNode* hashList[MAX_HASH_SIZE];
int ELFHash(char* str);
int main()
{
char buffer[512];
LNode* p;
int i=0;
while(gets(buffer)){
if(sscanf(buffer,"%s%s",dict[i].english,dict[i].foreign)!=2){
break;
}
else{
int key=ELFHash(dict[i].foreign);
p=new LNode();
p->ind=i;
p->next=hashList[key];
hashList[key]=p;
i++;
}
}
while(gets(buffer)!=NULL){
int key=ELFHash(buffer);
p=hashList[key];
while(p!=NULL){
if( strcmp(buffer,dict[p->ind].foreign)==0){
break;
}
p=p->next;
}
if(p==NULL){
printf("eh\n");
}
else{
printf("%s\n",dict[p->ind].english);
}
}
return 0;
}
int ELFHash(char* str)
{
unsigned long h=0;
while(*str!='\0'){
h=(h<<4)+(*str);
str++;
unsigned long g=h&0xf0000000L;
if(g!=0){
h^=g>>24;
}
h&=~g;
}
return h%MAX_HASH_SIZE;
}
poj 2503.Babelfish
最新推荐文章于 2022-04-09 22:28:03 发布