POJ3461 KMP快速字符串匹配
来源:互联网 发布:美国大数据上市公司 编辑:程序博客网 时间:2024/05/16 09:52
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;const int dmax=1000100;char s[dmax],p[dmax];int next[dmax];void get_next(char *p){int k=-1,j=0,n=strlen(p);next[0]=-1;while (j<n){if (k==-1 || p[k]==p[j]){k++;j++;if (p[j]!=p[k])next[j]=k;else next[j]=next[k];}else k=next[k];}}int kmp(char *s,char *p){int i=0,j=0,x=strlen(s),y=strlen(p),ans=0;get_next(p);while (i<x){if (j==y){ans++;j=next[j];}if (j==-1 || s[i]==p[j]){i++;j++;}else j=next[j];}if (j==y)ans++;return ans;}int main(){int T;scanf("%d",&T);getchar();while (T--){memset(p,0,sizeof(p));memset(s,0,sizeof(s));memset(next,0,sizeof(next));gets(p);gets(s);printf("%d\n",kmp(s,p));}return 0;}
0 1
- POJ3461 KMP快速字符串匹配
- POJ3461 Oulipo(字符串匹配KMP)
- poj3461 KMP算法(字符串匹配)
- KMP快速字符串匹配
- poj3461 hash字符串匹配
- KMP-字符串快速匹配算法
- POJ3461-字符串匹配(基础)
- POJ3461-串匹配-经典的KMP
- KMP快速字符串匹配 (next数组优化)
- poj3461(KMP)
- POJ3461 KMP
- KMP+poj3461
- poj3461 KMP
- poj3461 KMP
- poj3461 KMP
- POJ3461 KMP
- poj3461 KMP
- POJ3461 字符串之模式匹配,kmp,求目标串中有多少个位置可重叠的子串
- 从头认识Spring-1.11 注入List或Set(这个例子比较体现代码复用)
- 代码冲突解决工具BeyondCompare的在SourceTree中的配置方法
- Command-Line Flags
- QGIS源码编译问题
- Android EventBus 的项目使用
- POJ3461 KMP快速字符串匹配
- Protocol Buffer技术详解(语言规范)
- 本地方法(JNI)——数值参数与返回值
- bug记录:httpclient-invalid query
- Android多媒体文件扫描流程
- GitHub 优秀的 Android 开源项目
- 特别的生存法则 人脉
- C/C++ sort函数的用法
- Linux vmstat命令实战详解