hdu2087
来源:互联网 发布:linux 进程启动时间 编辑:程序博客网 时间:2024/05/16 16:08
#include <stdio.h>#include <string.h>const int maxn=2000;int f[maxn],p[maxn];void getfail(char *s){ f[0]=0; f[1]=0; int len=strlen(s); for(int i=1;i<len;i++) { int j=f[i]; while(j&&p[j]!=p[i]) j=f[j]; f[i+1]=p[i]==p[j]?j+1:0; }}int ans=0;void find(char *p,char *t){ int j=0; int n=strlen(p),m=strlen(t); getfail(p); for(int i=0;i<m;i++) { while(j&p[j]!=t[i]) j=f[j]; if(p[j]==t[i]) j++; if(j==n){ j=0; ans++; } }}int main(){ char t[1000],p[1000]; while(scanf("%s",t)==1){ if(t[0]=='#') break; if(scanf("%s",p)){ ans=0; find(p,t); printf("%d\n",ans); } } return 0;}
3 0
- hdu2087
- hdu2087
- hdu2087
- hdu2087
- hdu2087
- HDU2087
- hdu2087
- HDU2087
- hdu2087(KMP)
- hdu2087(kmp)
- hdu2087 暴力
- 【HDU2087】【KMP】
- java hdu2087
- hdu2087--kmp
- hdu2087 剪花布
- hdu2087-剪花布条
- hdu2087 剪花布条
- HDU2087 剪花布条
- 操作xml文档的通用方法
- Exception in thread “commons-pool-EvictionTimer”
- 用文件函数获取文件的大小代码片段
- 算法系列(十三)图论基本概念和拓扑排序
- HYSBZ 1036 树链剖分
- hdu2087
- jsp与servlet传值相关问题
- 【剑指offer】二叉搜索树与双向链表
- Rabbitmq 学习笔记(二)队列
- C2. Brain Network (medium)
- use delegate to update UI
- Wooden Sticks(贪心)
- React Native 高质量学习资料汇总
- Java并发编程与技术内幕