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:求测试数据In Reply To:Re:求测试数据 Posted by:sths at 2012-04-25 21:33:03 > 发下代码。。我帮你看看。。 我使用链地址法写的HASH,不知道为什么WA,麻烦你了哈。。。 #include<stdio.h> #include<stdlib.h> #include<string.h> #define max 100100 #define mod 9983 typedef struct HASH { char f[12],e[12]; struct HASH *next; HASH() { next=NULL; } }hashtable; hashtable *Hash[max]; void insert(char *s1,char *s2) { int key=0,i; for(i=0;*s2;i++) key+=*(s2++)*i; key%=mod; if(!Hash[key]) { hashtable* pn=new hashtable; strcpy(pn->e,s1); strcpy(pn->f,s2); Hash[key]=pn; } else { hashtable* pn=Hash[key]; while(pn->next) pn=pn->next; hashtable *temp=new hashtable; strcpy(temp->e,s1); strcpy(temp->f,s2); pn->next=temp; } } void find(char *s1) { int key=0,i; for(i=0;*s1;i++) key+=*(s1++)*i; key%=mod; if(!Hash[key]) { printf("eh\n"); return ; } else { hashtable *temp=Hash[key]; while(temp) { if(!strcmp(temp->f,s1)) { printf("%s\n",temp->e);return ; } temp=temp->next; } } } int main() { //freopen("in.txt","r",stdin); char s1[12],s2[12]; memset(Hash,0,sizeof(Hash)); while(scanf("%c",&s1[0]),s1[0]!='\n') { scanf("%s%s",s1+1,s2); insert(s1,s2); getchar(); } while(scanf("%s",s1)==1) { find(s1); //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