[模板]kmp[poj3461][codevs5757]
来源:互联网 发布:无网络摄像头安装方法 编辑:程序博客网 时间:2024/06/07 02:50
codevs5757
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int MAXN = 1000000 + 50;char s1[MAXN],s2[MAXN];int next[MAXN];int n,m,ans;int main(){ scanf("%s",s1 + 1); scanf("%s",s2 + 1); n = strlen(s1 + 1); m = strlen(s2 + 1); for(int i = 2;i <= n;i ++){ int p = next[i - 1]; while(p && s1[p + 1] != s1[i])//失配,寻找最长前缀 p = next[p]; if(s1[p + 1] == s1[i])// p ++; next[i] = p; } int p = 0; for(int i = 1;i <= m;i ++){ while(p && s1[p + 1] != s2[i]) p = next[p]; if(s1[p + 1] == s2[i]) p ++; if(p == n) ans ++; } printf("%d",ans); return 0;}
阅读全文
0 0
- [模板]kmp[poj3461][codevs5757]
- poj3461 kmp 模板题
- poj3461 KMP模板题
- poj3461 kmp模板题
- POJ3461 【KMP(粗糙模板)】
- POJ3461 Oulipo KMP模板
- KMP算法模板+POJ3461实现
- POJ3461(KMP模板题)
- POJ3461(KMP模板题)
- poj3461 KMP模板 或 哈希
- poj3461 (裸kmp)kmp模板
- kmp模板---poj3461
- poj3461(KMP)
- POJ3461 KMP
- KMP+poj3461
- poj3461 KMP
- poj3461 KMP
- poj3461 KMP
- Python3.可迭代对象_迭代器_生成器
- css 隐藏元素的方法
- 编程的那些事儿(三)
- C++实现双向链表
- [Flink]Flink1.3 Stream指南七 理解事件时间与Watermarks
- [模板]kmp[poj3461][codevs5757]
- 70. Climbing Stairs
- Intel workshop 所看所想
- SQLServer跟踪
- POJ
- 公众号学习进度
- leetcode之 Judge Route Circle
- [Flink]Flink1.3 Stream指南八 图解事件时间与Watermarks
- 民航安保项目