#include<iostream>
#include<string>
using namespace std;
typedef unsigned long long ull;
const int N = 100010;
ull p[N], h[N];
const int base = 131;
int n;
ull hash1(string a, int max1)
{
ull sum = 0;
for (int i = 1; i < max1; i++)
{
if (a[i] >= '0' && a[i] <= '9')
sum += sum * base + a[i] - '0' + 1;
if (a[i] >= 'a' && a[i] <= 'z')
sum += sum * base + a[i] - 'a' + 11;
if (a[i] >= 'A' && a[i] <= 'Z')
sum += sum * base + a[i] - 'A' + 37;
}
return sum;
}
int main()
{
cin >> n;
p[0] = 1;
for (int i = 1; i <= 1600; i++)
{
p[i] = p[i - 1] * base;
}
int k = 0;
while (n--)
{
string str;
cin >> str;
ull t = hash1(str, str.size());
int flag = 1;
for (int i = 0; i < k; i++)
{
if (h[i] == t)
{
flag = 0;
break;
}
}
if (flag)
h[k++] = t;
}
cout << k;
}
刷题日记 洛谷3370 哈希字符串
最新推荐文章于 2024-11-11 19:42:06 发布