| ||||||||||
| 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 | |||||||||
Re:求数据,一直wa谁帮我看一下是怎么回事In Reply To:求数据,一直wa谁帮我看一下是怎么回事 Posted by:201158080209 at 2012-06-12 16:59:44 > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator