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[i]即可。再逆序输出。
 #include<stdio.h>
#include<string.h>
int Next[],n;
char p[];
int ans[],pos; void prekmp() {
n=strlen(p);
int i,j;
j=Next[]=-;
i=;
while(i<n) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
Next[++i]=++j;
}
} int main() {
//freopen("in","r",stdin);
while(~scanf("%s",p)) {
pos=;
prekmp();
for(int i=n;Next[i]>;i=Next[i]) {
ans[pos++]=Next[i];
}
for(int i=pos-;i>=;i--)
printf("%d ",ans[i]);
printf("%d\n",n);
}
}

kuangbin专题十六 KMP&&扩展KMP POJ2752 Seek the Name, Seek the Fame的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

随机推荐

  1. java常用八大排序法

    最近查资料发现java排序挺有意思的,其中包含常见八种具有代表性的排序法:笔者觉得排序的功能重要,但更重要的是排序的思想:所以简单叙述一下常见排序方法名称,并用代码举例. A.插入排序(直接插入排序. ...

  2. Spring装配各种类型bean

    一.单属性值的装配 //setter注入,提供无参构造器,提供setXX方法 <property name="" value=""></pro ...

  3. 昨天的笔试题, StringBuffer

    代码: public static void switchStr(StringBuffer x, StringBuffer y) { x.append(y); System.out.println(& ...

  4. js语法和数据类型

    基础知识(Basics) JavaScript 的很多语法借鉴自 Java,但也受 Awk,Perl 和 Python 影响. JavaScript 是大小写敏感的,使用 Unicode 字符集. 在 ...

  5. Android中的文件读写总结

    在Android中,文件主要分为两大类,内部存储和外部存储 内部存储的文件是程序私有的,分为普通文件和Cache文件 外部文件也可以是私有的,也可以是共有的,这要根据文件的目录位置来决定 共有文件可以 ...

  6. Codeforces #505(div1+div2) C Plasticine zebra

    题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...

  7. CodeForces 1109C. Sasha and a Patient Friend

    题目简述:维护以下三种操作 1. "1 t s":在时刻$t$插入命令$s$.保证任意操作后,任意时刻至多只有一个命令. 2. "2 t":删除时刻$t$的命令 ...

  8. uniqid() 函数 和 microtime()函数

    uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.语法 uniqid(prefix,more_entropy) 参数     描述prefix     可选.为 ID 规定前缀.如果 ...

  9. 如何使CPU占用率为50%

    在Linux下,CPU的状态分为系统态,用户态和空闲态,分别指系统内核执行时间,处于用户态的时间和空闲系统进程执行的时间.三者之和就是CPU的总时间. CPU的利用率就是非空闲进程占用时间的比例. 1 ...

  10. UltraISO制作系统ISO镜像

    一.简介 UltraISO是一款功能强大而又方便实用的光盘映像文件制作/编辑/转换工具,它可以直接编辑ISO文件和从ISO中提取文件和目录,也可以从CD-ROM制作光盘映像或者将硬盘上的文件制作成IS ...