#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define F(i,n) for(int i=1;i<=n;i++)
#define Ff(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef unsigned long long ull;
ull mod1=19260817,mod2=19660813;
int ans=1,base=33;
char s[10001];
struct data
{
ull x,y;
}hash[10001];
ull hash1(char s[])
{
int l=strlen(s);
ull ans=0;
Ff(i,l)
ans=(ans*base+(ull)s[i])%mod1;
return ans;
}
ull hash2(char s[])
{
int l=strlen(s);
ull ans=0;
Ff(i,l)
ans=(ans*base+(ull)s[i])%mod2;
return ans;
}
int cmp(data a,data b)
{
return a.x<b.x;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%s",s);
hash[i].x=hash1(s);
hash[i].y=hash2(s);
}
sort(hash+1,hash+1+n,cmp);
for(int i=2;i<=n;i++)
{
if(hash[i].x!=hash[i-1].x||hash[i].y!=hash[i-1].y)
ans++;
}
cout<<ans;
}
经过我地毯式搜索发现,如果把cmp比较器中的a.x<b.x改成a.y<b.y,就能过了。 这是为什么?