字符串Hash模板

博主链接

#include
#include
#define ll long long int
using namespace std;
ll gethash(char *s,int m){
	ll h=0;
	for(int i=0;s[i];i++)
	h=((h<<8)+s[i])%m;
	return h;
}
int main(){
	#ifdef LOCAL
		//freopen("C:/Users/Administrator/Desktop/input.txt","r",stdin);
	#endif
	char a[100]="22222222222222222222222222222";
	char b[100]="22222222222222222222222223222";
	printf("%lld\n",gethash(a,1e9+7));
	printf("%lld\n",gethash(b,1e9+7));
}


你可能感兴趣的:(字符串模版)