博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj-------------(2752)Seek the Name, Seek the Fame(kmp)
阅读量:4538 次
发布时间:2019-06-08

本文共 2250 字,大约阅读时间需要 7 分钟。

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

Description

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

ababcababababcababaaaaa

Sample Output

2 4 9 181 2 3 4 5

Source

,Zeyuan Zhu
 
代码:
1     #include
2 #include
3 #include
4 #include
5 using namespace std; 6 const int maxn= 400050; 7 int next[maxn]; 8 int ans[maxn]; 9 char str[maxn];10 int main()11 {12 int i,j;13 while(scanf("%s",str)!=EOF&&*str!='.')14 {15 j=-1;16 i=0;17 next[i]=-1;18 int len=strlen(str);19 while(i
0)35 {36 // printf("%d\n",i);37 ans[cnt++]=i;38 i=next[i];39 }40 for(i=cnt-1;i>0;i--)41 printf("%d ",ans[i]);42 printf("%d\n",ans[0]);43 }44 return 0;45 }
View Code

 

转载于:https://www.cnblogs.com/gongxijun/p/3878387.html

你可能感兴趣的文章
C# 笔记
查看>>
2013年10月13日学习:SQL通过命令语句来创建表
查看>>
剑指offer : 二维数组中的查找
查看>>
第三章 python基础
查看>>
java基础题
查看>>
[转]人人店短信插件开发
查看>>
[转]c# System.IO.Ports SerialPort Class
查看>>
14. 最长公共前缀
查看>>
Redis文档
查看>>
项目重构
查看>>
(笔试题)和一半的组合数
查看>>
leetcode--Algorithm--Array_Part 1 Easy- 566 Reshape the Matrix
查看>>
AC自动机算法详解 (转载)
查看>>
python3-day5(模块)
查看>>
Linux配置JDK
查看>>
qt 读取xml文件
查看>>
python3之正则表达式
查看>>
Visual Studio提示“无法启动IIS Express Web服务器”的解决方法
查看>>
Java 时间总结
查看>>
jQuery EasyUI 拖放 – 基本的拖动和放置
查看>>