https://www.luogu.org/problemnew/show/P3370
自然溢出
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 typedef long long ll; 7 ll base=19260817; 8 ll a[10010]; 9 string s; 10 int n, ans=1; 11 ll hashs(string s){ 12 int len=s.size(); 13 ll ans=0; 14 for (int i=0; i<len; i++) 15 ans=ans*base+(ll)s[i]; 16 return ans&0x7fffffff; 17 } 18 int main(){ 19 scanf("%d",&n); 20 for (int i=1; i<=n; i++){ 21 cin>>s; 22 a[i]=hashs(s); 23 } 24 sort(a+1, a+n+1); 25 for(int i=2; i<=n; i++) 26 if(a[i]!=a[i-1]) ans++; 27 printf("%d ",ans); 28 return 0; 29 }