hdu 2087 剪花布条 kmp
来源:互联网 发布:java 第三方登录 实例 编辑:程序博客网 时间:2024/05/18 13:08
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;void getfail(char *p,int *f){ int m=strlen(p); f[0]=0; f[1]=0; for(int i=1; i<m; i++) { int j=f[i]; while(j&&p[i]!=p[j]) j=f[j]; f[i+1]=p[i]==p[j]?j+1:0; }}int kmp(char *t,char *p,int *f){ int cnt=0,i,j,n=strlen(t),m=strlen(p); getfail(p,f); for(i=0,j=0; i<n; i++) { while(j&&p[j]!=t[i]) j=f[j]; if(p[j]==t[i]) j++; if(j==m) { cnt++; j=0; } } return cnt;}int main(){ char t[1024],p[1024]; int f[1024]; while(~scanf("%s",t)) { if(strcmp(t,"#")==0) break; scanf("%s",p); printf("%d\n",kmp(t,p,f)); } return 0;}
0 0
- HDU 2087 剪花布条 kmp
- HDU 2087 剪花布条(KMP)
- HDU 2087 剪花布条 KMP
- hdu 2087 剪花布条(KMP)
- HDU 2087 剪花布条 裸KMP
- HDU 2087 剪花布条 KMP
- hdu 2087 剪花布条(KMP)
- HDU 2087 剪花布条(KMP)
- HDU 2087 剪花布条(KMP:贪心)
- HDU-2087 剪花布条(kmp)
- HDU 2087 剪花布条 KMP入门
- HDU 2087 剪花布条 //简单kmp
- hdu 2087 剪花布条 KMP
- HDU 2087 剪花布条 KMP题解
- hdu 2087 剪花布条(数据结构:KMP)
- hdu 2087 剪花布条 KMP
- HDU - 2087 剪花布条 (KMP)
- hdu 2087 剪花布条 KMP
- Spring和MyBatis环境整合
- 深入理解JavaScript系列(16):闭包(Closures)
- Keystore密钥库
- Dart网络编程-备忘录2.0
- 数据是企业的无价财富——爱数备份存储柜服务器的初体验(图文)
- hdu 2087 剪花布条 kmp
- Android开发工具之adt-bundle-windows
- Keil中的Code,RO,RW,ZI分别表示什么?
- 提升Android ListView性能的几个技巧
- 深入理解JavaScript系列(12):变量对象(Variable Object)
- Java基础
- 深入理解JavaScript系列(11):执行上下文(Execution Contexts)
- 深入理解JavaScript系列(10):JavaScript核心(晋级高手必读篇)
- 使用pb的connection对象建立TCP连接