pku 3461 Oulipo (裸kmp匹配)
来源:互联网 发布:淘宝航空箱定做 编辑:程序博客网 时间:2024/05/22 16:41
题目:http://poj.org/problem?id=3461
题意:求W在Z出现的次数。
主串 W A Z A /0
-1 0 0 1
模式串T A Z A Z A Z A
next可以让其主串中的正确位置与T下一个字符匹配。
#include<stdio.h>#include<string.h>const int maxn=1000005;char T[maxn],W[10005];int next[10005];void get_next(int len){ int i=0,j=-1; next[0]=-1; while(i<len){ if(j==-1||W[i]==W[j]){ i++; j++; next[i]=j; } else j=next[j]; }}int main(){ int n,i,j; scanf("%d",&n); while(n--){ scanf("%s",W); scanf("%s",T); int ans=0; int len1=strlen(W),len2=strlen(T); get_next(len1); i=0; j=0; while(i<len2){ if(j==-1||T[i]==W[j]) /*还是如此,只有这里才能i++,即让i往后移。移完之后如果还不匹配,再赋为-1,让其得以往后移。但每回匹配时,j已经变回0了*/ i++,j++; else j=next[j]; if(j==len1) ans++,j=next[j]; /*完全匹配成功和匹配失败都要改变下标j,使W中正确的位置与T匹配*/ } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- pku 3461 Oulipo (裸kmp匹配)
- pku 3461 Oulipo(KMP)
- Pku oj 3461 Oulipo(kmp)
- POJ 3461 Oulipo(KMP匹配)
- POJ 3461 Oulipo(KMP求匹配次数)
- 字符串匹配之KMP算法(POJ 3461 Oulipo)
- Oulipo poj 3461 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 Oulipo(KMP)
- Poj 3461 Oulipo (KMP)
- POJ---3461-Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- input框变为不可编辑状态
- Stepping Thread Group插件介绍
- oracle查看表空间
- Linux对tomcat的启动、关闭、杀死
- 微信小程序 仿美团城市选择 城市切换
- pku 3461 Oulipo (裸kmp匹配)
- arduino如何在ssd1306上显示中文字符
- 解析程序的健壮性和鲁棒性
- python day02 变色字体进度条输出
- ros源码分析(6)—roslaunch Commandline Tools
- android基于监听的事件处理机制
- Win10 下安装 TensorFlow 遇到的一些问题
- 设计模式(23)-访问者模式
- 移动端flex 经典布局