Oulipo----poj3461(kmp模板)
2015-09-23 20:56
351 查看
题目链接:http://poj.org/problem?id=3461
和 减花布条 的题对比一下;
求s2中s1的个数kmp模板;
View Code
和 减花布条 的题对比一下;
求s2中s1的个数kmp模板;
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> using namespace std; const int N = 1e6+7; char s1 , s2 ; int n, m, ans; int Next ; void GetNext() { int i = 0, j = -1; Next[i] = j; while(i<n) { if(j==-1 || s2[i] == s2[j]) Next[++i] = ++j; else j = Next[j]; } } void kmp() { int i = 0, j = 0; while(i<m) { if(j==-1 || s1[i] == s2[j]) i++,j++; else j = Next[j]; if(j == n) { ans++; j=Next[j]; } } } int main() { int T; scanf("%d", &T); while(T--) { scanf("%s%s", s2, s1); m = strlen(s1); n = strlen(s2); GetNext(); ans = 0; kmp(); printf("%d\n", ans); } return 0; }
View Code
相关文章推荐
- CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)
- java02
- in App Purchases一个注意事项
- ActiveMQ - message cursor
- 读取Json文件为String字符串
- Java——随机计数器
- 大道至简第二章读后感
- html5 构造网页的新方式
- 安卓几种界面布局的详解
- 交叉线还是直通线?
- UVA 1356 Bridge 自适应辛普森
- rt-thread学习笔记(二)-LED测试程序
- Android基础学习之SQLiteHelper(数据库帮助类)
- 逆袭系列日志说明-20150923
- 自定义TabBarController
- ASP.NET Session的共享
- java01
- PCB元件快速分类排列方法
- 我的Android之旅——学习、项目、心态
- linux网卡做bond的7种模式