BKDRHash

一个简单的hash

#include <iostream>
#include <cstdio>
using namespace std;
unsigned ans=0;
unsigned BKDRHash(char *str)
{
    unsigned seed = 131; // 31 131 1313 13131 131313 etc..
    unsigned hash = 0;
    while (*str)hash = hash * seed + (*str++);
    return (hash & 0x7FFFFFFF);
}
int main()
{
	scanf("%s",a);
	ans=BKDRHash(a);
	printf("%u\n",ans);
	return 0;
}


猜你喜欢

转载自blog.csdn.net/ghode_dave/article/details/51261167