#include <iostream>
#include <algorithm>
#include <functional>
#define int long long
const int N = 30010, P = 131;
using namespace std;
int n, res, a[N];
string s;
int hash_(string s)
{
int h = 0;
for (int i = 0; s[i]; i ++ )
{
h = h * P + (long long)s[i];
}
return h & 0x7fffffff;
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
cin >> s;
a[i] = hash_(s);
}
sort(a + 1, a + n + 1, greater<int>());
res = 1;
for (int i = 2; i <= n; i ++ )
{
if (a[i] != a[i - 1]) res ++;
}
cout << res << endl;
}
[模板] 字符串hash
于 2023-04-07 21:41:09 首次发布