| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
HSAH无限WA啊~~求强力数据~~求解释啊#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define HashTableSize 99991
char aa[20],bb[20];
char cc[20];
char w[40];
typedef class HashTable
{
public :
char str1[20],str2[20];
HashTable *next;
HashTable()
{
next=0;
memset(str1,0,sizeof(str1));
memset(str2,0,sizeof(str2));///
}
}Hashtable;
Hashtable * hash[100005];
unsigned int ELFHash (const char *str)
{
unsigned int key=0;
unsigned int x=0;
while(*str)
{
key=(key<<4)+(*str++);
if((x=key&0xF0000000L)!=0)
{
key^=(x>>24);
key&=~x;
}
}
return key&0x7fffffff;
}
void hash_insert(char aaa[],char bbb[])
{
int key=ELFHash(bbb)%HashTableSize+1;
if(!hash[key])
{
Hashtable *temp =new Hashtable ;
//temp->str1=aaa;
strcpy(temp->str1,aaa);
strcpy(temp->str2,bbb);
hash[key]=temp;
}
else
{
Hashtable *temp=hash[key];
while(temp->next)
temp=temp->next;
temp->next=new HashTable;
strcpy(temp->str1,aaa);
strcpy(temp->str2,bbb);
}
}
bool hash_find(char ccc[])
{
int key=ELFHash(ccc)%HashTableSize;
if(!hash[key])
return false;
else
{
Hashtable *temp=hash[key];
while(temp)
{
if(strcmp(temp->str2,ccc)==0)
{
printf("%s\n",temp->str1);
return true;
}
temp=temp->next;
}
}
return false;
}
int main()
{
memset(hash,0,sizeof(hash));
/*while(1)
{
if((aa[0]=getchar())=='\n')break;
scanf("%s%s",aa+1,bb);
insert(aa,bb);
//getchar();
}*/
while(gets(w) && w[0]!=0)
{
sscanf(w,"%s %s",aa,bb);
hash_insert(aa,bb);//add(a,b);
}
while(scanf("%s",cc)!=EOF)///
{
if(!hash_find(cc))
printf("eh\n");
}
return 0;}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator