poj Oulipo(KMP)
来源:互联网 发布:mac桌面文件丢失 编辑:程序博客网 时间:2024/05/22 02:21
题目连接:http://poj.org/problem?id=3461
题意:有两个字符串,ch1,ch2(strlen(ch1)<=strlen(ch2));求ch2中有多少个子串和ch1相同
解题思路:如果单纯的用string里面的find()函数的话特定超时,所以可以用kmp算法。
#include<iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;#define M 10001int t[M];string s,ch;void next(){int x=s.length();int k=-1;t[0]=-1;for(int i=1;i<x;i++){while(k>-1&&s[i]!=s[k+1])k=t[k];if(s[i]==s[k+1])k++;t[i]=k;}}void KMP(){int sum=0;int m=0;int x=ch.length();int j=-1;int flat=0;for(int i=m;i<x;i++){while(j>-1&&ch[i]!=s[j+1])j=t[j];if(ch[i]==s[j+1])j++;if(j==s.length()-1){j=t[j];sum++;}}cout<<sum<<endl;}int main(){int n;cin>>n;while(n--){cin>>s>>ch;next();KMP();}}
- poj 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)
- 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算法)
- kmp算法(POJ 3461 Oulipo)
- 有密码和用户名却进不去共享文件(在进去过共享文件后,又修改了密码,导致没有共享文件的登录框)
- CAsyncSocket使用总结 收藏
- MySql分页存储过程
- 111116 VB WebBrowser 加入
- MySQL存储过程的控制语句
- poj Oulipo(KMP)
- Android Pixelflinger 研究
- Java多线程之Callable接口的实现
- ubuntu--fetion--qq
- ASP.NET内置对象
- c++的点点滴滴(1)----关于类型转换
- 程序流程控制
- Android 的GUI 系统
- MySQL存储过程的基本函数