POJ 3461 Oulipo (kmp入门)
来源:互联网 发布:java框架整合 编辑:程序博客网 时间:2024/06/04 20:05
上数据结构才学KMP算法。。。
刷一道练习题。。。
#include<cstdio>#include<iostream>#include<cstring>#define M 1000000+10#define N 10000+10using namespace std;char w[N];char t[M];int next[N];int cnt;void get_next(int len){ int i=1,j=0; next[1]=0; while(i<=len) { if(j==0 || w[i]==w[j]) { ++i;++j; if(w[i]!=w[j]) next[i]=j; else next[i]=next[j]; } else j=next[j]; }}void KMP(){ int L1=strlen(w+1),L2=strlen(t+1); //cout<<"L1="<<L1<<" "<<"L2="<<L2<<endl; int i = 1,j=1; while(j<=L1 && i<=L2) { if(j==0 || t[i]==w[j]) { ++i; ++j; } else j=next[j]; if(j==L1+1) { cnt++; j = next[j]; } }}int main(){ int T,ll,tmp; scanf("%d",&T); getchar(); while(T--) { memset(w,0,sizeof(w)); memset(t,0,sizeof(t)); memset(next,0,sizeof(next)); gets(w+1); gets(t+1); ll = strlen(w+1); get_next(ll); cnt=0; KMP(); printf("%d\n",cnt); } return 0;}
- POJ 3461 Oulipo (kmp入门)
- poj 3461 Oulipo(简单的kmp入门)
- poj 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo---kmp
- POJ 3461 Oulipo KMP
- poj 3461 Oulipo (KMP)
- POJ 3461 Oulipo ( KMP )
- POJ 3461 Oulipo KMP
- POJ 3461 Oulipo / KMP
- Oulipo - POJ 3461 KMP
- 【KMP】 POJ 3461 Oulipo
- KMP---POJ 3461Oulipo
- POJ 3461 Oulipo (KMP)
- poj 3461 Oulipo kmp
- 【KMP】POJ-3461 Oulipo
- KMP POJ-3461 Oulipo
- poj-3461 Oulipo 【kmp】
- ubuntu常用的命令
- <iostream.h>和<isotream>的区别
- HDU-2066 一个人的旅行 最短路
- Python里的闭包和AOP
- Qt曲线相关知识
- POJ 3461 Oulipo (kmp入门)
- 动态分配内存空间过程
- 各种sql在pig中的实现
- 使用Matlab显示OV5642输入的Raw Bayer图像
- 关于UbuntuServer重置root密码的方法
- wifi几个术语
- Android的系统架构
- Microsoft Visual C++ 和 Borland C++ Builder 之比较
- Tcp 断开连接