poj 2752 Seek the Name, Seek the Fame
来源:互联网 发布:l女装淘宝店名 编辑:程序博客网 时间:2024/06/01 16:02
求字符串的前缀和后缀相同的前-后缀长度
kmp算法的应用,求出的next数组即为最长的前缀和后缀相同的前-后缀长度,递归求next数组,直到不存在这样的前后缀,每次得到的数组即为一种满足题意的前后缀长度,数组不包含该字符串本身的长度,即最大的前后缀长度为数组长度。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;void getNext(char *str,int *next){int j = 0;int len = strlen(str);next[1] = 0;for(int i = 2;i<len+1;i++){while(j>0&&str[j]!=str[i-1]){j = next[j];}if(str[j]==str[i-1])j++;next[i] = j;}}char str[400005];int next[400005];void Output(int len){if(next[len]==0)return;Output(next[len]);printf("%d ",next[len]);}int main(){while(scanf("%s",str)!=EOF){getNext(str,next);int len = strlen(str);Output(len);printf("%d\n",len);}}
- poj seek the name,seek the fame
- poj---Seek the Name, Seek the Fame
- Seek the Name, Seek the Fame POJ
- Seek the Name, Seek the Fame POJ
- POJ-2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752--Seek the Name, Seek the Fame (next)
- POJ:2752Seek the Name, Seek the Fame
- POJ 2752 - Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ-2752-Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame---kmp
- VIJOS P1351 棋盘制作
- 为C6713建立一个简单的工程
- URAL 1169. Pairs 图中抽象出数学公式dfs
- 谈Objective-C Block的实现
- HDU--杭电--1195--Open the Lock--深搜--忘记说句话装逼了,都是什么双向广搜,不知道怎么想的,直接就是一个深搜的水题好不好?
- poj 2752 Seek the Name, Seek the Fame
- oracle死进程查找与删除方法
- 【总结】文本文件与二进制文件读取的区别
- UNIX网络编程卷二 笔记 Posix消息队列
- Kubuntu下关闭触摸板
- g_idle_add函数介绍
- Effective Java 第16条 : 复合优先于继承
- 程序猿装B指南
- java环境变量设置