The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:

Step1. Connect the father's name and the mother's name, to a new string S. 
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).

Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)

Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab
aaaaa

Sample Output

2 4 9 18
1 2 3 4 5 题意:求出前缀后缀一样的对应字符的位置,按递增顺序输出
prefix-suffix:前后缀的意思。。。
 //ababcababababcabab
#include<stdio.h>
#include<iostream>
#include<set>
#include<string.h>
using namespace std;
const int N=; int s[N];
char t[N];
int nextt[N]; void getnext(int len)//求的是模式串的next数组
{
int i=,j=-;
nextt[]=-;
while(i<len)
{
if(j<||t[i]==t[j])
nextt[++i]=++j;
else
j=nextt[j];
}
} int main()
{
while(~scanf("%s",t))
{
int len=strlen(t);
getnext(len);
// for(int i=0; i<len; i++)
// cout<<nextt[i]<<"**"<<endl;
int p=;
for(int i=len; i!=; )
{
s[p++]=nextt[i];
i=nextt[i];
}
p--;
for(int i=p-; i>=; i--)
printf("%d ",s[i]);
printf("%d\n",len);
memset(s,'\0',sizeof(s));
memset(t,,sizeof(t));
memset(nextt,'\0',sizeof(nextt));
}
return ;
}

POJ-2752-Seek the Name-kmp的变形的更多相关文章

  1. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...

  2. POJ 2752 Seek the Name, Seek the Fame (KMP next 数组 变形)

    题意:给一个字符串S,判断在什么下标的时候,前缀和后缀相等,输出前缀和后缀相等的点. 分析:next数组的一种很巧妙的用法 next数组表示的意义是当前下标前面k字符和开头的前面k个字符相等 所以就会 ...

  3. 【kmp+求所有公共前后缀长度】poj 2752 Seek the Name, Seek the Fame

    http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 ...

  4. POJ 2752 Seek the Name, Seek the Fame (KMP)

    传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...

  5. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  6. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

  7. poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Ac ...

  8. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

  9. POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)

    题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...

  10. POJ 2752 Seek the Name, Seek the Fame kmp(后缀与前缀)

    题意: 给你一个串T,找出串T的子串,该串既是T的前缀也是T的后缀.从小到大输出所有符合要求的串的长度. 分析: 首先要知道KMP的next[i]数组求得的数值就是串T中的[1,i-1]的后缀与串T中 ...

随机推荐

  1. redis数据库操作

    一.String(字符串)操作 String在redis中的存储是按照key-value的形式存储 1.SET key value [EX seconds] [PX milliseconds] [NX ...

  2. vue.js 2.0 --- 安装node环境,webpack和脚手架(入门篇)

    1.环境搭建 1.1.安装node.js 1.2 安装过程很简单,一路“下一步”就可以了.安装完成之后,打开命令行工具(win+r,然后输入cmd),输入 node -v,如下图,如果出现相应的版本号 ...

  3. CF696B Puzzles(期望dp)

    传送门 解题思路 比较有意思的一道题.首先假如这个点\(x\)只有\(1\)个儿子\(u\),那么显然可得\(dp[u]=dp[x]+1\).继续如果多加一个儿子\(p\),那么\(p\)在\(u\) ...

  4. (转)当android调试遇到ADB server didn't ACK以及顽固的sjk_daemon进程 .

    转:http://blog.csdn.net/wangdong20/article/details/20839533 做Android调试的时候经常会遇到,程序写好了,准备接上手机调试,可不一会儿出现 ...

  5. POJ2516费用流

    目录 目录 (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 目录 题意:传送门 AC代码: #include <iostream> #include <cstdio ...

  6. Java-Class-C:java.util.ArrayList

    ylbtech-Java-Class-C:java.util.ArrayList 1.返回顶部 1.1. import java.util.ArrayList;import java.util.Lis ...

  7. ionic-CSS:ionic tab(选项卡)

    ylbtech-ionic-CSS:ionic tab(选项卡) 1.返回顶部 1. ionic tab(选项卡) ionic tab(选项卡) 是水平排列的按钮或者链接,用以页面间导航的切换.它可以 ...

  8. bash数组总结

    bash数组操作 bash支持两种数组,一种是索引数组,一种是关联数组 索引数组 数组的值类型是任意的,索引也未必一定要连续,当做列表理解更好 下面总结下索引数组,即列表: 1. 声明 declare ...

  9. hexo next修改代码区主题,修改字体样式,大小

    文章目录 广告 修改代码区主题 站点_config.yml 主题_config.yml 修改字体样式,大小 ps 我自己的方式 广告 本人博客地址:https://mmmmmm.me 源码:https ...

  10. unittest(2)

    测试用例执行顺序 1.setUp和tearDown相关 setUp:表示前置条件,它在每一个用例执行之前必须会执行一次        setUp可以理解为我们需要自动化测试时,需要打开网页窗口,输入对 ...