| ||||||||||
| 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 | |||||||||
怎么用hash就一直WA啊?#include <cstdio>
#include <cstring>
#include <memory>
const int M = 300000;
char dic[M][25];
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;
}
int main()
{
char fl[25],tmp[25],ch;
int i,j;
memset(dic,'#',sizeof(dic));
while(1)
{
ch = getchar();
if(ch == '\n')
break;
scanf("%s %s",tmp,fl);
i = ELFhash(fl);
dic[i][0] = ch;
j = 0;
while(tmp[j])
{
dic[i][j+1] = tmp[j];
j++;
}
dic[i][j+1] = '\0';
getchar();
}
while(scanf("%s",tmp) != EOF)
{
i = ELFhash(tmp);
if(dic[i][0] == '#')
printf("eh\n");
else
printf("%s\n",dic[i]);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator