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

那位牛头帮忙看看这个代码哪里错了啊,ORZ

Posted by zhanglongpan at 2010-02-20 22:30:49 on Problem 2503
#include <stdio.h>
#include <string.h>
int hash[160001];
char engl[150001][14];
int hashFunction(char* str)
{
	unsigned long h = 0, g;
	int nKeyLength=strlen(str);
	char *arEnd=str+nKeyLength; 
	
	while (str<arEnd) 
	{ 
		h = (h << 4) + *str++; 
		if ((g = (h & 0xF0000000)))
		{ 
			h = h ^ (g >> 24);
			h = h ^ g; 
		} 
	}
	h=h%149999;
	return h;


}

int main()
{
	memset(hash,0,sizeof(hash));
	char fo[14],en[14],test[14],buff[50];
	int j=1;
	while (gets (buff) && strcmp (buff, "") != 0)
	{
		sscanf(buff,"%s%s",en,fo);
		int index=hashFunction(fo);
		int k=0;
		while(engl[index][0]!='\0')
		{
			index++;
			k++;
		}
		hash[index-k]=k;
		strcpy(engl[index],en);
	}
	while(gets(test))
	{
		int i=hashFunction(test);
		if(engl[i+hash[i]][0]!='\0')
		{
			printf("%s\n",engl[i+hash[i]]);
		}
		else
			printf("eh\n");
	}	
	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