HDU2087【KMP-next】
来源:互联网 发布:ubuntu安装分区设置 编辑:程序博客网 时间:2024/04/28 03:09
思路:
利用next[]的转化。
//#include <bits/stdc++.h>#include<cstdio>#include<string.h>#include<algorithm>using namespace std;const int N=1e3+10;char p[N],s[N];int lenp,lens,Next[N];void GetNext(){ int i=0,j=-1; Next[0]=-1; while(i<lenp) { if(j==-1||p[i]==p[j]) Next[++i]=++j; else j=Next[j]; }}int KMP(){ int i=0,j=0,ans=0; while(i<lens) { if(j==-1||s[i]==p[j]) { i++; j++; if(j==lenp) { ans++; j=0; } } else j=Next[j]; } return ans;}int main(){ while(scanf("%s",s)) { if(strcmp(s,"#")==0) break; scanf("%s",p); lens=strlen(s); lenp=strlen(p); GetNext(); printf("%d\n",KMP()); } return 0;}
0 0
- HDU2087【KMP-next】
- hdu2087(KMP)
- hdu2087(kmp)
- 【HDU2087】【KMP】
- hdu2087--kmp
- hdu2087(kmp裸题)
- HDU2087(KMP)
- HDU2087--KMP模板题
- hdu2087 KMP+简单动归
- hdu2087 剪花布条--KMP
- HDU2087 剪花布条 [KMP]
- hdu2087 剪花布条 KMP
- hdu2087 剪花布条 kmp
- hdu2087剪花布条[KMP]
- hdu2087 剪花布条【kmp】
- HDU2087--剪花布条 (KMP)
- KMP next
- HDU2087-剪花布条(KMP算法)
- python自动将数据库表结构转换成markdown文档
- Android HorizontalGridView焦点问题及探索
- poj 2184 Cow Exhibition (01背包)
- 下一个排列-lintcode
- Drect3D---多游戏模型的载入
- HDU2087【KMP-next】
- Android基础类之BaseAdapter
- 【PAT】1052. Linked List Sorting
- woshi111
- 新的开始
- 1月14日
- PAT A1009 Product of Polynomials(25)
- git基础
- 综合:bool类型 命名空间 输入输出