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用得不对还是这题不能用hash#include<stdio.h> #include<string.h> #include<memory.h> const int maxn=54117; const int maxs=20010; int a[maxs],hash[maxn],b[maxs]; int n,m; int ELFhash(char *key) { unsigned long h=0; while(*key) { h=(h<<4)+*key++; unsigned long g=h&0Xf0000000L; if(g) h^=g>>24; h&=~g; } return h%maxn; } int main() { int i,key,cn; char s[23]; while(scanf("%d%d",&n,&m)!=EOF) { if(n==0) break; cn=0; memset(hash,255,sizeof(hash)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0;i<n;i++) { scanf("%s",s); key=ELFhash(s); if(hash[key]==-1) { hash[key]=cn; a[hash[key]]++; cn++; } else a[hash[key]]++; } for(i=0;i<cn;i++) b[a[i]]++; for(i=1;i<=n;i++) printf("%d\n",b[i]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator