博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu——1358Period(kmp专练)
阅读量:4048 次
发布时间:2019-05-25

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

Period

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5845    Accepted Submission(s): 2835
Problem Description
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as A
K , that is A concatenated K times, for some string A. Of course, we also want to know the period K.
 
Input
The input file consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1 000 000) – the size of the string S. The second line contains the string S. The input file ends with a line, having the number zero on it.
 
Output
For each test case, output “Test case #” and the consecutive test case number on a single line; then, for each prefix with length i that has a period K > 1, output the prefix size i and the period K separated by a single space; the prefix sizes must be in increasing order. Print a blank line after each test case.
 
Sample Input
3aaa12aabaabaabaab0
 
Sample Output
Test case #12 23 3Test case #22 26 29 312 4
 
Recommend
JGShining
kmp的扩展运用
#include
#include
#include
#include
using namespace std;int nexta[1000111];void getnext(string s){ int i=0,j=-1; nexta[0]=-1; while(i
>k&&k!=0) { cin>>s; getnext(s); cout<<"Test case #"<
<
1)//看是否循环 { cout<
<<" "< //找出重复次数大于1时的位置 并且输出重复次数
++jj;cout<<endl;}return 0;}/*一个字符串,问从头到某个位置,字符串的前缀最多重复了多少次。比方aaaa的字符串,到第二个字符,前缀a重复了两次,到第三个字符,前缀a重复了三次,到第四个字符,前缀a重复了四次,前缀aa重复了两次,但我们要得到的是重复了四次。*/
 

转载地址:http://itfci.baihongyu.com/

你可能感兴趣的文章
Springboot的仓库管理系统——计算机类专业课程设计(毕业设计)
查看>>
刷新页面实现方式总结(HTML,ASP,JS)
查看>>
根据地球上两个地点的经度和纬度,如何获得这两点的距离?
查看>>
COM组件的使用
查看>>
关于文件夹的手动隐藏和恢复
查看>>
JavaScript和Jscript的版本及规范
查看>>
WinCE 对 Java脚本的支持
查看>>
XML学习
查看>>
ASP中LIST控件
查看>>
ASP中按钮触发事件
查看>>
学习:GPIO口模拟I2C
查看>>
展望2007
查看>>
做个男人
查看>>
转:S3C2410 bootloader ----VIVI阅读笔记
查看>>
转:嵌入式系统 Boot Loader 技术内幕
查看>>
ARM 的宏定义
查看>>
SIGN UP BEC2
查看>>
S3C2440中对LED驱动电路的理解
查看>>
《天亮了》韩红
查看>>
Windows CE下USB摄像头驱动开发(以OV511为例,附带全部源代码以及讲解) [转]
查看>>