poj3461—KMP裸题
来源:互联网 发布:unity3d 捏脸系统 编辑:程序博客网 时间:2024/05/16 12:08
题目大意:给出两个字符串p和s,求出p在s中出现的次数
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;char p[10010],s[1000010];int next[10010];int lenp,lens,ans,m;void getnext(){ next[0]=-1; int j=-1; for (int i=1;i<lenp;i++) { while (j>-1 && p[j+1]!=p[i]) j=next[j]; if (p[j+1]==p[i]) j++; next[i]=j; }}int KMP(){ int j=-1,count=0; for (int i=0;i<lens;i++) { while (j>-1 && p[j+1]!=s[i]) j=next[j]; if (p[j+1]==s[i]) j++; if (j==lenp-1) { count++; j=next[j]; } } return count;}int main(){ scanf("%d", &m); while (m--) { scanf("%s%s", p,s); lenp=strlen(p); lens=strlen(s); getnext(); ans=KMP(); printf("%d\n", ans); }}
注:真实的next数组是程序中的next数组值+1
1 0
- poj3461—KMP裸题
- 【poj3461】kmp裸题
- POJ3461 Oulipo KMP裸题
- POJ3461[Oulipo]KMP裸题
- poj3461 Oulipo —— KMP
- poj3461(KMP)
- POJ3461 KMP
- KMP+poj3461
- poj3461 KMP
- poj3461 KMP
- poj3461 KMP
- POJ3461 KMP
- poj3461 KMP
- POJ3461:Oulipo(MP,KMP裸题)
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(kmp)
- viewutils fragment invalid value for field
- UVa 489 Hangman Judge
- 计算多边形与圆的面积交
- 线程和指针
- 分页效果
- poj3461—KMP裸题
- Map的遍历方式
- cocos2dx[3.2]——裁剪节点ClippingNode
- poj2406—KMP next数组的性质求最小周期
- CodeForces 266A Stones on the Table
- QT选择文件对话框实现多种类型文件匹配过滤
- JavaWeb — HTML
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- 245,键盘处理