hdu 2087 kmp
来源:互联网 发布:mp3音量增大软件 编辑:程序博客网 时间:2024/06/04 23:28
求不重叠的模式串有多少个。
#include<stdio.h>#include<string>#include<string.h>#include<algorithm>#include<iostream>using namespace std;#define maxn 1000006int f[10005];char s1[maxn],s2[maxn];int cnt;void net(int n){ // int n=strlen(s2); int j=0; f[0]=0; f[1]=0; // cout<<"fuck"<<endl; for(int i=2;i<n;i++) { j=f[i-1]; while(j&&s2[i-1]!=s2[j]) j=f[j]; // cout<<"fuck"<<endl; if(s2[i-1]==s2[j]) f[i]=j+1; else f[i]=0; }}int kmp(int n,int m){ int n1=n; int n2=m; int j=0; int i=0; for(i=0;i<n1;i++) { while(j&&s1[i]!=s2[j]) j=f[j]; if(s1[i]==s2[j]) j++; if(j==n2) { j=0; cnt++; } } return cnt;}int main(){ while(scanf("%s",s1)!=EOF) { cnt=0; if(s1[0]=='#'&&s1[1]=='\0') break; scanf("%s",s2); int n=strlen(s1); int m=strlen(s2); net(m); cout<<kmp(n,m)<<endl; } return 0;}
0 0
- HDU 2087 水KMP
- HDU-2087(KMP)
- hdu 2087 kmp
- HDU 2087 KMP
- 【2087 HDU KMP 】
- HDU 2087 KMP裸题
- HDU 2087 kmp
- hdu 2087 kmp
- hdu 2087 KMP
- hdu 2087 水kmp
- HDU 2087 (KMP)
- HDU 2087(KMP)
- 字符串 KMP HDU 2087
- HDU - 2087 KMP
- KMP 模板 hdu 2087
- HDU 2087 (KMP||暴力)
- 两个kmp hdu 2594 & hdu 2087
- hdu 2087 BF 和 KMP算法
- EXCEL里常用的几个正则表达式
- 公众号的代码编写过程
- ORACLE甲骨文招聘高级软件开发工程师
- SOJ.Concatenation and substring
- VMWare虚拟机下为Ubuntu 12.04.1配置静态IP(NAT方式)
- hdu 2087 kmp
- java中resultset
- Android 中自定义软键盘
- Tomcat全攻略(TOMCAT详细教程)
- 让软件像树一样成长起来而非像房子一样建造起来
- 截取带括号和逗号的字符串
- 基督徒十一奉献是不是必须奉献教会?信徒可不可以拿自己要十一奉献钱去帮助别人呢?
- CSS3 Transform & Transition & Animation
- RichFaces 简介