跳到主要内容

字符串哈希

参考资料

实现

197 Bcpp
using ull=unsigned long long;
const int base=131;
const ull mod=212370440130137957;
ull get_hash(string s)
{
ull res=0;
for(int i=0;i<s.size();i++)
{
res=(res*base+s[i])%mod;
}
return res;
}

例题

如题,给定 NN 个字符串(第 ii 个字符串长度为 MiM_i,字符串内包含数字、大小写字母,大小写敏感),请求出 NN 个字符串中共有多少个不同的字符串。

给定 nn 个字符串,判断不同的字符串有多少个。