POJ 3461 Oulipo(KMP统计子串出现次数)
来源:互联网 发布:js防水怎么样 编辑:程序博客网 时间:2024/06/07 19:21
题目链接:poj3461
题目大意:
典型的KMP 统计模式串在主串中出现的次数
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespace std;#define maxn 1000010#define mem(a,val) memset(a,val,sizeof (a) )char w[maxn],t[maxn];int wlen,tlen;int nexts[maxn];void getnexts(){int j,k; j=0; k=-1; nexts[0]=-1; while(j<wlen) { if(k==-1||w[j]==w[k]) { nexts[++j]=++k; } else k=nexts[k]; }}int kmp(){int ans=0;int i,j;if(wlen==1&&tlen==1){if(w[0]==t[0])return 1;else return 0;}getnexts();for(i=0,j=0;i<tlen;i++){while(j>0&&t[i]!=w[j])j=nexts[j];if(t[i]==w[j])j++;if(j==wlen){ans++;j=nexts[j];}}return ans;}int main(){ int cas; scanf("%d",&cas); while(cas--){mem(nexts,0);scanf("%s%s",w,t);wlen=strlen(w);tlen=strlen(t);printf("%d\n",kmp());} return 0;}
阅读全文
0 0
- POJ 3461 Oulipo(KMP统计子串出现次数)
- POJ 3461 Oulipo(KMP:统计一个串出现的次数)
- POJ 3461 Oulipo【KMP,子串出现次数,可重叠】
- POJ 3461 Oulipo (KMP字符串匹配·统计p在s中出现次数)
- POJ 3461 Oulipo(KMP 一个串在另一个串出现的次数(可重叠|不可))
- kmp统计子串出现次数
- [KMP求模式在主串出现次数]POJ 3461 Oulipo
- POJ 3461 Oulipo (KMP,求模版串在文本串中可覆盖出现的次数,constructive)
- 【KMP算法】KMP统计子串出现次数
- POJ 3461 Oulipo(KMP求匹配次数)
- POJ 3461 Oulipo【KMP】【模板题】(找出第一个字符串在第二个字符串中出现次数)
- POJ 3461 - Oulipo(KMP)
- POJ-3461 Oulipo(KMP)
- Poj 3461 Oulipo (KMP)
- POJ---3461-Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- 【POJ 3461】Oulipo(kmp)
- 图片轮播jquery , 支持html5 , 滑动手势, 屏幕大小自适配 , 横排 竖排图片自适应, 竖排图片居中显示
- c++四种类型转换方式
- 线程--(1)ThreadLocal简单使用
- <需要补充学习的资料>: AVL tree , Tire tree(前缀树(prefix tree),后缀树(suffix tree)),radix tree, aho-corasick
- C#之枚举类型总结
- POJ 3461 Oulipo(KMP统计子串出现次数)
- 【数据】Marvell 88W8686 WiFi模块的固件数据
- [霍尔定理]「2017 山东一轮集训 Day2」LOJ 6062——PAIR
- 如何利用github打造博客专属域名
- scala基础总结
- 到银联的调试过程,总结,记录
- 应届生求职指南(一)- 序言
- iOS WKWebView 与 js 交互
- Inkscape将位图转换为矢量图