Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎么用hash就一直WA啊?

Posted by youngtrips at 2007-10-05 10:02:21 on Problem 2503
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator