poj3461——Oulipo(kmp)
来源:互联网 发布:淘宝水晶店哪家是真的 编辑:程序博客网 时间:2024/06/06 01:46
传送门:点我
题目大意:给你两个字符串p和s,求出p在s中出现的次数。
贴代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define N 10006#define NN 1000003char s[NN],s1[N];int Next[N];void make_Next(int n){ int i,j; for(i=1,j=0; i<n; i++) { while(j>0&&s1[i]!=s1[j]) j=Next[j-1]; if(s1[i]==s1[j]) j++; Next[i]=j; }}int main(){ int t,j,k; cin>>t; while(t--) { int num=0; scanf("%s",s1); scanf("%s",s); int len=strlen(s1); Next[0]=0; make_Next(len); int len1=strlen(s); for(j=0,k=0; k<len1; k++) { while(j>0&&s1[j]!=s[k]) j=Next[j-1]; if(s1[j]==s[k]) j++; if(j==len) { num++; j=Next[j-1];//j=0从头,abcabcabca和abca } } printf("%d\n",num); } return 0;}
阅读全文
0 0
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(KMP)
- poj3461——Oulipo(kmp)
- poj3461 Oulipo —— KMP
- poj3461 Oulipo(KMP)
- 【poj3461】Oulipo(KMP)
- poj3461 Oulipo(KMP)
- 【POJ3461】Oulipo(KMP)
- Oulipo(poj3461)(KMP)
- Oulipo (poj3461,简单KMP)
- POJ3461——Oulipo
- C++——KMP算法例题——Oulipo(POJ3461)
- POJ3461——Oulipo KMP算法的应用
- POJ3461:Oulipo(MP,KMP裸题)
- 【KMP】 poj3461 Oulipo
- 【KMP】Oulipo POJ3461
- poj3461 Oulipo (kmp)
- 测试啊
- 读写文件时00 0A与80 0A的bug
- MyBatis + maven org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- CSS 的优先级机制[总结]
- 判断三点顺序(顺时针或者逆时针)(模板)
- poj3461——Oulipo(kmp)
- Spring Scheduled + Redis 实现分布式定时器(一)
- 自定义View系列目录索引
- Redis应用场景
- [拓扑序] Educational Codeforces Round 25 825E. Minimal Labels
- Java中serialVersionUID的作用
- 统计学习方法-朴素贝叶斯法(基于R的实现)
- centos6.9-vsftpd安装配置
- sizeof strlen wcslen tcslen 比较