kmp poj 3461
来源:互联网 发布:动态sql防止sql注入 编辑:程序博客网 时间:2024/05/22 12:59
这是一道KMP的水题,还没明白KMP是怎么回事 ==,先贴了代码,明天继续研究。
#include <stdio.h>#include <string.h>const int MaxN = 1000010;char word[MaxN/10], txt[MaxN];int next[MaxN/10];void KMP_next(char b[], int pre[]){ int n = (int)strlen(b), k; pre[0] = -1; k = -1; for(int i = 1; i < n; i++) { while(k > -1 && b[k+1] != b[i]) k = pre[k]; if(b[k+1] == b[i]) k++; pre[i] = k; }}int main(){ int n; for(scanf("%d%*c", &n); n--;) { gets(word); gets(txt); KMP_next(word, next); int cnt = 0, len = (int)strlen(word); for(int i = 0, j = -1; txt[i]; ++i) { while(j > -1 && word[j+1] != txt[i]) j = next[j]; if(word[j+1] == txt[i]) j++; if(j == len-1) { cnt++; j = next[j]; } } printf("%d\n", cnt); } return 0;}
0 0
- 【KMP模板】POJ 3461
- poj 3461 KMP
- poj 3461 Oulipo(KMP)
- kmp poj 3450 3461
- POJ 3461 KMP
- POJ 3461 kmp
- POJ 3461 Oulipo(KMP)
- poj 3461 kmp
- POJ 3461 Oulipo---kmp
- POJ 3461 Oulipo KMP
- poj 3461 Oulipo (KMP)
- POJ 3461 Oulipo ( KMP )
- POJ 3461 裸KMP
- 【POJ 3461 KMP】
- KMP poj 3461
- kmp poj 3461
- POJ 3461 Oulipo KMP
- POJ 3461 Oulipo / KMP
- bootstrap的一些属性问题
- 常用的webservice接口
- [Asm]设置字体样式
- Java 内存溢出详解
- Transaction table及TX锁
- kmp poj 3461
- Test
- C++引用与指针的关系
- mfc 关于不响应键盘消息的处理
- 给mysql修改登录密码
- Telerik控件入门 第一个Button
- CMD命令之ECHO大全
- 动态分区式存贮区管理算法实现
- solr的安装windows 7,tomcat6应用服务器