poj 3461 Oulipo KMP算法
来源:互联网 发布:三星n7100支持4g网络吗 编辑:程序博客网 时间:2024/05/16 12:46
题目:给出一个单词w和一篇文章t,求该单词在文章中出现了多少次(可以有重叠部分)。
分析:很裸的KMP算法,现求出w的next数组,再进行匹配,匹配次数即为答案。
下面附程序:
var w,t:ansistring; lenw,lent,i,n,j,l,ans:longint; next:array[0..10000] of longint;procedure get;var i,j:longint;begin next[0]:=-1; next[1]:=0; i:=2; j:=0; while i<=lenw do if (j=-1)or(w[j+1]=w[i]) then begin inc(j); next[i]:=j; inc(i); end else j:=next[j];end;begin readln(n); for l:=1 to n do begin readln(w); readln(t); lenw:=length(w); lent:=length(t); get; ans:=0; i:=1; j:=0; while i<=lent do begin if (j=-1)or(w[j+1]=t[i]) then begin inc(j); inc(i); end else j:=next[j]; if j=lenw then begin inc(ans); j:=next[j]; end; end; writeln(ans); end;end.
0 0
- 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)
- poj 3461 Oulipo 字符串匹配 KMP算法
- POJ 3461&& hiho1015 Oulipo [KMP算法]
- KMP算法 学习例题 POJ 3461Oulipo
- 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
- HDOJ 1003 在本地编译是正确的,请大神看看我的程序错在哪里
- mysql函数大全
- hdu2099 整除的尾数
- ubuntu如何安装 tar,gz tar.gz2
- oracle truncate table 和delete from table 的 不同点 以及 truncate table 在存储过程里面的用法
- poj 3461 Oulipo KMP算法
- Andriod基本框架
- Spring单实例、多线程安全、事务解析
- cc(self)是什么?
- 【C++】STL--LIST
- ARM-LINUX-GCC 4.4.3安装(ubuntu下)
- java处理高并发高负载类网站的优化方法
- 特征矩
- QPSK调制发送数据包