-
参考源码:HDOJ- HDUACM2010版_14,关于Hash及应用
资源介绍
参考源码(HDOJ-1800)
// by linle
#include "stdio.h"
#include "memory.h"
#define MAXN 7003
inline int ELFhash(char *key)
{
unsigned long h = 0;
unsigned long g;
while( *key )
{
h =( h<< 4) + *key++;
g = h & 0xf0000000L;
if( g ) h ^= g >> 24;
h &= ~g;
}
return h;
}
int hash[MAXN],count[MAXN];
int maxit,n;
inline void hashit(char *str)
{
int k,t;
while( *str == '0' ) str++;
k = ELFhash(str);
t = k % MAXN;
while( hash[t] != k && hash[t] != -1 )
t = ( t + 10 ) % MAXN;
if( hash[t] == -1 ) count[t] = 1,hash[t] = k;
else if( ++count[t] > maxit ) maxit = count[t];
}
int main()
{
char str[100];
while(scanf("%d",&n)!=EOF)
{
memset(hash,-1,sizeof(hash));
for(maxit=1,gets(str);n>0;n--)
{
gets(str);
hashit(str);
}
printf("%d\n",maxit);
}
}