字符串hash模板题【Olipo】

Oulipo

https://ac.nowcoder.com/acm/problem/108058

题目大意:给出一个匹配串S和一个字符串T,问匹配串在字符串中出现了几次 经典的字符串匹配问题,可以用KMP,BM,Sunday等各种方法解决,但是我觉得字符串哈希才是最好写最好理解的。。 先将匹配串hash一遍 然后从字符串的第一位开始,判断第i位和匹配串的第一位是否相同,相同的话对字符串的第i到第i+strlen(s)-1位hash,看哈希值是否相同 相同的话ans++

#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<set>
#include<bitset>
#include<vector>
using namespace std;
#define ull unsigned long long

#define  LL long long
const int maxn=1000010;
ull base =131;

char S[maxn];
char T[maxn];
ull g[maxn];
ull p[maxn];

ull Hash(char s[])
{
    int len=strlen(s);
    ull ans=0;

    g[0]=s[0];
    for(int i=1;i</vector></bitset></set></stack></sstream></queue></map></cmath></cstring></cstdio>
全部评论

相关推荐

爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
一tiao酸菜鱼:秋招还没正式开始呢,就准备有结果了。。。。?
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-05 15:27
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务