洛谷 P3370 字符串哈希

目录:

  • 题目:
  • 分析:
  • 代码:


题目:

传送门


分析:

就是用 hash h a s h 表就好了。


代码:

// luogu-judger-enable-o2
#include
#include
#include
#include  
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
inline LL read() {
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
const unsigned long long mod=212370440130137957ll;
const unsigned long long bace=131;
char s[1501];
unsigned long long ans;
unsigned  long long hahe(char s[])
{
    int len=strlen(s);
    ans=0;
    for(int i=0;iunsigned long long)s[i])%mod;
    return ans;
}
int a[10001];
int main()
{
    int n=read();
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        a[i]=hahe(s);
    }   
    sort(a+1,a+1+n);
    int king=0;
    for(int i=1;iif(a[i]!=a[i+1]) king++;
    printf("%d",king+1);
    return 0;
}

你可能感兴趣的:(哈希表)