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
/*题意:求既匹配字符串前缀又匹配后缀的字符
串的长度
思路:其实next[]数组就表示的是最长的前缀和后缀匹配,
那么只要next[]数组的值不为0的话,
就代表有前后缀匹配,递归下去,
当然整个字符串也符合条件*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 400010;
char s[maxn];
int next[maxn], flag,l1;
void getnext(int l)
{
int i=0,j=-1;
next[0]=-1;
while(i<l)
{
if(j==-1||s[i]==s[j])
{
i++,j++;
next[i]=j;
}
else
j=next[j];
/*此时t[j] != t[k] ,
所以就有 next[j+1] < k,
那么求 next[j+1] 就等同于求 t[j]
往前小于 k 个的字符与
t[k] 前面的字符的最长重合串,
即 t[j-k+1] ~ t[j] 与 t[0] ~ t[k-1] 的最长重合串,
那么就相当于求 next[k]
}*/
}
void dfs(int x)
{
if(x==0) return ;
dfs(next[x]);
if (!flag)
{
printf("%d",x);
flag = 1;
}
else printf(" %d",x);
}
int main()
{
while(~scanf("%s",s))
{
int l1=strlen(s);
getnext(l1);
flag=0;
dfs(l1);
printf("\n");
}
}

D - Seek the Name, Seek the Fame的更多相关文章

  1. 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 ...

  2. poj-------------(2752)Seek the Name, Seek the Fame(kmp)

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

  3. 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 ...

  4. Seek the Name, Seek the Fame(Kmp)

    Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (J ...

  5. 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 ...

  6. poj2752 Seek the Name, Seek the Fame(next数组的运用)

    题目链接:id=2752" style="color:rgb(202,0,0); text-decoration:none; font-family:Arial; font-siz ...

  7. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

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

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

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

  9. POJ 2751:Seek the Name, Seek the Fame(Hash)

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

  10. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

随机推荐

  1. 【函数分享】每日PHP函数分享(2021-1-8)

    explode() 使用一个字符串分割另一个字符串. array explode( string $delimiter , string $string [, int $limit ]) 参数描述de ...

  2. Solon rpc 之 SocketD 协议 - 消息应答模式

    Solon rpc 之 SocketD 协议系列 Solon rpc 之 SocketD 协议 - 概述 Solon rpc 之 SocketD 协议 - 消息上报模式 Solon rpc 之 Soc ...

  3. python作业完成简单的文件操作

    题目 请创建以学号命名的目录,在该目录中创建名称为file1.txt的文件,并将自己的个人信息(序号.姓名以及班级)等写入该文件:然后并读取文件中的内容到屏幕上:接着重新命名该文件为file2.txt ...

  4. Linux 使用命令行上传下载文件

    基本语法: 服务器: 用户名@ip:/路径 scp 要拷贝的文件 要存放的文件 上传文件到服务器 # 把本地 source.md 文件上传到 152.116.113.13 服务器的/home目录 # ...

  5. 【SpringBoot】Spring Boot 集成SwaggerAPI

    Spring Boot 集成SwaggerAPI 文章目录 Spring Boot 集成SwaggerAPI Swagger 添加依赖 配置类 config 控制类 controller 接口测试 页 ...

  6. 理解Go的多态实现

    总结两点: 在Go中,定义一个interface类型,该类型说明了它有哪些方法.使用时,在函数中,将该interface类型作为函数的形参,任意一个实现了interface类型的实参都能作为该inte ...

  7. MATLAB中load和imread的读取方式区别

    load是导入文件,一般从mat文件中,读取的是结构体imread是图像处理工具箱的库函数,处理图像比较方便,读取的是矩阵 1.之前将数组或者矩阵保存为一个mat格式的文件,在进行load命令读取时: ...

  8. 001.IT运维面试问题-Linux基础

    Linux基础 简述Linux主流的发行版? Redhat.CentOS.Fedora.SuSE.Debian.Ubuntu.FreeBSD等. 简述Linux启动过程? ⑴开机BIOS自检,加载硬盘 ...

  9. Eclipse在线安装FatJar插件失败解决方案

    在线安装fatjar(URL:http://kurucz-grafika.de/fatjar) 快要安装完的时候报错如下: 找了很久解决方法,终于有了下文:很是粗乎意料呃,下载一个eclipse2.0 ...

  10. 【链表】leetcode-1290-二进制链表转整数

    leetcode-1290-二进制链表转整数 题目描述 给你一个单链表的引用结点 head.链表中每个结点的值不是 0 就是 1.已知此链表是一个整数数字的二进制表示形式. 请你返回该链表所表示数字的 ...