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

求数据,一直wa谁帮我看一下是怎么回事

Posted by 201158080209 at 2012-06-12 16:59:44 on Problem 2503
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define maxn 100003
typedef struct THashTable
{
	char en[12];
	char dia[12];
	THashTable* next;
}HashTable;
HashTable* hash[maxn];
int ELFhash(char *k)//经典的字符串哈希
{
	unsigned long h=0,g;
	while(*k)
	{
		h=(h<<4)+*k++;
		g=h&0xf0000000L;
		if(g)
			h^=g>>24;
		h&=~g;
	}
	return h%maxn;
}
void insert(char* te,char* td)
{
	int h=ELFhash(td);
	if(!hash[h])
	{
		HashTable* temp=(HashTable*) malloc(sizeof(HashTable));
		strcpy(temp->en,te);
		strcpy(temp->dia,td);
		temp->next=0;
		hash[h]=temp;
	}
	else
	{
		HashTable* temp=hash[h];
		temp->next=(HashTable*) malloc(sizeof(HashTable));
		temp->next->next=0;
		strcpy(temp->next->en,te);
		strcpy(temp->next->dia,td);
	}
}
void find(char* temStr)
{
	int h=ELFhash(temStr);
	HashTable* temp=hash[h];
	while(temp)
	{
		if(strcmp(temp->dia,temStr)==0)
		{
			printf("%s\n",temp->en);
			return;
		}
		temp=temp->next;
	}
	printf("en\n");
}
int main()
{
	memset(hash,0,sizeof(hash));
	char english[12];
	char dialog[12];
	char t;
	while(1)
	{
		t=getchar();
		if(t=='\n') break;
		english[0]=t;
		t=getchar();
		if(t==' ')
		{
			scanf("%s",dialog);
			english[1]='\0';
		}
		else{
			english[1]=t;
		scanf("%s %s",english+2,dialog);
		}
		getchar();//以防敲下的回车被下次的t吸收
		insert(english,dialog);
	}
	char temStr[12];
	while(scanf("%s",temStr)!=EOF)
	{
		find(temStr);
		getchar();
	}
	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