P3370 【模板】字符串哈希

链接:Miku

-------------------------------

#include<iostream> 
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const unsigned long long k=131,imp=1e7+1;
unsigned long long n;
string now;
unsigned long long  hash[1000005];
unsigned long long anss;
void deal(string s,int kk){
    unsigned long long l=s.length(),ans=0;
    for(unsigned long long i=0;i<l;++i)
        ans=ans*k+(unsigned long long)s[i];
    hash[kk]=ans%0x7fffffff;
}
int main(){
    cin>>n;
    for(unsigned long long i=1;i<=n;++i){
        cin>>now;
        deal(now,i);
    }
    sort(hash+1,hash+1+n);
    for(int i=1;i<=n;++i){
        if(hash[i]!=hash[i+1]){
        anss++;
        }
    }
    cout<<anss;
    return 0;
}

 

posted @ 2020-07-30 15:06  Simex  阅读(96)  评论(0编辑  收藏  举报