HDU 1686 - Oulipo(kmp)
来源:互联网 发布:maya编程语言 编辑:程序博客网 时间:2024/05/23 14:14
Problem link
分析:
kmp匹配
代码:
#include <cstdio>#include <cstring>const int maxn = 1000010;char w[maxn], t[maxn];int _next[maxn];void get_next() { int w_len = strlen(w); int i = 0, j; _next[0] = j = -1; while (i < w_len) { if (j == -1 || w[j] == w[i]) { i++; j++; _next[i] = j; } else { j = _next[j]; } }}int get_times(){ int ans = 0; int w_len = strlen(w); int t_len = strlen(t); int i = 0, j = 0; while (j < t_len) { if (i == -1 || w[i] == t[j]) { i++; j++; } else { i = _next[i]; } if (i == w_len) { ans++; i = _next[i]; } } return ans; }int main() { int T; scanf("%d", &T); while (T--) { memset(w, 0, sizeof(w)); memset(t, 0, sizeof(t)); memset(_next, 0, sizeof(_next)); scanf("%s %s", w, t); get_next(); printf("%d\n", get_times()); } return 0;}
0 1
- HDU 1686 Oulipo (kmp)
- hdu 1686 kmp Oulipo
- KMP hdu-1686-Oulipo
- Hdu 1686 Oulipo[kmp]
- hdu 1686 Oulipo(KMP)
- HDU-1686-Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- HDU 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- HDU - 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- HDU 1686--Oulipo【KMP】
- hdu 1686 Oulipo【kmp】
- hdu 1686 Oulipo(kmp)
- HDU 1686:Oulipo 【KMP】
- HDU 1686 - Oulipo(kmp)
- hdu 1686 Oulipo(KMP)
- LUA中的数学库介绍
- GCD之队列的选择和与主线程之间的通信
- android小问题: Notification通知栏 中用Intent传值无效
- 信管考试笔记之一
- 开源选型之Android三大图片缓存原理、特性对比
- HDU 1686 - Oulipo(kmp)
- Freemarker中将字符串转换为数字number
- windows wamp运行提示 Fatal error: Call to undefined function curl_init的解决方法
- actionbar设置背景图片和文字颜色
- 运行地址和加载地址
- 第四周 项目1 建立单链表
- [笔记] Convex Optimization 2015.10.14
- 自己写的第一本Linux教程,也小小的班门弄斧一下
- linux学习笔记--centos 安装