POJ 3461 Oulipo
来源:互联网 发布:淘宝介入后买家输后果 编辑:程序博客网 时间:2024/06/06 12:46
给两个字符串,在目标串里找到模式串的个数。
#include <cstdio>#include <cstring>char text[1000005];char word[10005];int next[10005];//改进后的next数组,速度更快void get_next() { int j = -1, i = 0; next[0] = -1; while(word[i] != '\0') { if(j == -1 || word[j] == word[i]) { j++; i++; if(word[j] == word[i]) next[i] = next[j]; else next[i] = j; } else j = next[j]; }}int KMP(){ get_next(); int j = 0, i = 0; int ans = 0; int wlen = strlen(word); int tlen = strlen(text); while(i < tlen && j < wlen) { if(j == -1 || text[i] == word[j]) { i++; j++; } else j = next[j]; if(j == wlen) { ans++; j = next[j]; } } return ans;}int main(){ int T; scanf("%d",&T); while(T--) { memset(next,0,sizeof(next)); scanf("%s%s",word,text); printf("%d\n",KMP()); }}
0 0
- POJ 3461 Oulipo
- POJ-3461 Oulipo
- poj 3461 Oulipo
- poj 3461 Oulipo(KMP)
- poj 3461 Oulipo
- POJ-3461-Oulipo
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo
- POJ 3461 Oulipo
- POJ 3461 Oulipo
- POJ 3461 Oulipo---kmp
- POJ 3461 Oulipo KMP
- poj-Oulipo -3461
- POJ 3461 Oulipo
- POJ 3461 Oulipo
- POJ 3461 Oulipo
- poj 3461 Oulipo
- poj 3461 Oulipo
- Mac常用快捷键+设置
- Spring Ioc-依赖注入的几种方式
- 用shell简单处理文本的例子
- kmp算法c++实现
- MySQL之数据类型
- POJ 3461 Oulipo
- C语言练习题
- View平移动画的正确写法
- Jedis源码解析(ShardedJedis)
- Unity3d 开发(十)使用uTomate自动化打包流程
- JDK的安装与环境变量配置
- CF IndiaHack A 水题
- Python 数据结构与算法——deque(双端队列)
- B