For each prefix with length P of a given string S,if

S[i]=S[i+P] for i in [0..SIZE(S)-p-1],

then the prefix is a “period” of S. We want to all the periodic prefixs.

Input

Input contains multiple cases.

The first line contains an integer T representing the number of cases. Then following T cases.

Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.

Output

For each test case, first output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of periodic prefixs.Then output the lengths of the periodic prefixs in ascending order.

Sample Input

4
ooo
acmacmacmacmacma
fzufzufzuf
stostootssto

Sample Output

Case #1: 3
1 2 3
Case #2: 6
3 6 9 12 15 16
Case #3: 4
3 6 9 10
Case #4: 2
9 12
题意:求所有的循环节
思路:循环ans=ne[ans],len-ans
#include <iostream>
#include<string.h>
using namespace std;
const int maxn = 1e6+;
char a[maxn];
int ne[maxn],sum[maxn];
int main()
{
int t;
int num=;
scanf("%d",&t);
while(t--)
{
memset(ne,,sizeof(ne));
scanf("%s",a+);
int len=strlen(a+);
for(int i=,j=;i<=len;i++)
{
while(j&&a[i]!=a[j+]) j=ne[j];
if(a[i]==a[j+]) j++;
ne[i]=j;
}
int ans=len,cnt=;
while(ans)
{
ans=ne[ans];
sum[++cnt]=len-ans;
}
printf("Case #%d: %d\n",++num,cnt);
for(int i=;i<=cnt-;i++)
printf("%d ",sum[i]);
printf("%d\n",sum[cnt]);
}
return ;
}

Period II的更多相关文章

  1. (KMP Next的运用) Period II -- fzu -- 1901

    http://acm.fzu.edu.cn/problem.php?pid=1901 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=703 ...

  2. FZU1901 Period II —— KMP next数组

    题目链接:https://vjudge.net/problem/FZU-1901  Problem 1901 Period II Accept: 575    Submit: 1495Time Lim ...

  3. Fzu Problem 1901 Period II (kmp)

    题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...

  4. FZU - 1901 Period II(kmp所有循环节)

    Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SI ...

  5. [FZU 1901]Period II KMP

    For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the ...

  6. Q - Period II

    For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the ...

  7. Period II - FZU 1901(KMP->next)

    题目大意:给你一个字符串 S ,N = |S|,如果存在一个 P (1<=P<=N),并且满足 s[i] = s[P+i] (i = {0...N-P-1} ),求出来所有的 P 然后输出 ...

  8. FZU 1901 Period II(KMP循环节+公共前后缀)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要 ...

  9. FZU 1901 Period II(KMP中的next)题解

    题意:给你一串字符串,问你前后缀相同情况有几种,并输出后缀位置(?这里一直没看懂length是什么,但是这样理解答案也对,然后还要加上本身长度) 思路:这里好好讲讲next的用法.我们都知道next代 ...

随机推荐

  1. 计时器 GC垃圾回收 demo

    计时器: public void start() { //定义计时器 Timer timer=new Timer(); //定义运行间隔(数字越小,速度越快) int interval=30; //创 ...

  2. maven 三个仓库表

    https://search.maven.org ,http://www.mvnrepository.com/ http://maven.apache.org

  3. win7如何设置以管理员身份运行

    一.对所有程序以管理员身份运行 1.右键单击桌面“计算机”,选择“管理” 2.在页面左侧,依此打开“计算机管理(本地)→ 系统工具→本地用户和组→用户”,在右侧找到“Administrator”,双击 ...

  4. http response压缩

    http response压缩 一.Spring boot启用Gzip压缩 application.xml新增配置: 未启用压缩时试验接口传输大小不变为61.88M,耗时1分多钟 启动压缩时试验接口传 ...

  5. 【重点突破】—— UniApp 微信小程序开发官网学习One

    一.初步认识 uni-app官网:https://uniapp.dcloud.io/component/README HBuilderX官方IDE下载地址: http://www.dcloud.io/ ...

  6. leetcode-easy-array-283 move zeros

    mycode  77.24% class Solution(object): def moveZeroes(self, nums): """ :type nums: Li ...

  7. sed扩展命令使用

    [root@b ~]# cat f.txt inet addr:192.168.0.110 Bcast:192.168.0.255 Mask:255.255.255.0[root@b ~]# cat ...

  8. ERROR:imshow、Mat、waitkey找不到标识符(opencv)

    可以发现imshow.Mat.waitkey这三个都是opencv相关的. 在添加了相关库文件后还是有问题. #include "stdafx.h" #include <st ...

  9. Jenkins安装以及配置

    Jenkins介绍 Jenkins是一个java开发的.开源的.非常好用持续集成的工具,它能帮我们实现自动化部署环境.测试.打包等等的工作,还可以在构建任务成功或者失败之后给我们发邮件通知. 什么叫持 ...

  10. VS2010远程调试C#程序

    场景: 客户的计算机运行程序出现异常,由于办公场所不在一起,无法直接在客户的机器上调试.此时希望可以直接在开发人员的计算机(本地机器)上远程调试客户机上的软件. 假设: 本地机器的系统账户为 GIS, ...