【板子】字符串哈希

//lg p3370
//Copyright yeyou26
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long 

const ull p=998244353;

string s;
ull now_hash,v[100005];
int cnt,ans,n;

void get_hash()
{
    now_hash=0;
    ull now_p=1;
    for(int i=1;s[i];i++)
    {
        now_hash+=s[i]*now_p;
        now_p*=p;
    }
}

void do_compare()
{
    bool flag=0;
    for(int i=1;i<=cnt;i++)
    {
        if(v[i]==now_hash)
        {
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        ans++;
        v[++cnt]=now_hash;
    }
}

void solve()
{
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        get_hash();
        do_compare();
    }
    printf("%d",ans);
}
posted @   yeyou26  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示