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 |
求助,hash过不了#include<stdio.h> #include<string.h> #define mm 100000 struct hash1{ char s[11]; int key; }h[mm]; unsigned long long hash(char * str){ unsigned long long ans=0,i=0; while(str[i]!=0){ ans = ans * 26; ans += str[i]-'a'+1; ans = ans%13546+1; i++; } ans = ans%123546+6; return ans; } int main() { char str[25],str1[11],str2[11]; int a; while(gets(str)!=NULL&&str[0]!='\0') { sscanf(str,"%s %s",str1,str2); a=hash(str2); h[a].key=1; strcpy(h[a].s,str1); } while(gets(str)){ int i=hash(str); if(h[i].key==1) printf("%s\n",h[i].s); else printf("eh\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator