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 ;
}

最新文章

  1. Tip8:Unity中诸如 Awake() Start() Update()等函数的 执行顺序
  2. 9.装饰者模式(Decorator Pattern)
  3. 如何提取HTML代码中img的src地址?
  4. delphi TOpenDialog
  5. FMDB多线程读写问题,使用FMDataBaseQueue操作可以解决同时打开一个链接de读写问题
  6. git搭建服务器
  7. 网页标题(title)动态改变
  8. JS中的循环---最全的循环总结
  9. LR socket协议脚本
  10. UOJ#55. 【WC2014】紫荆花之恋 点分树 替罪羊树 平衡树 splay Treap
  11. UML中的六种关系
  12. python-浅拷贝和深拷贝
  13. Nginx技术研究系列5-动态路由升级版
  14. nginx_server_location对客户资源的辨别规则
  15. python 将文件描述符包装成文件对象
  16. css 让背景图片不停旋转
  17. STL - 函数作为算法的参数
  18. 船长带你看书——《selenium2 python 自动化测试实战》(1)
  19. 不能解决,复选框在request对象获取的信息后显示在用户信息里面为中文的选项名
  20. ffmpeg控制台上不能输出信息的解决办法

热门文章

  1. 参数类型*&amp;是什么意思?
  2. python3---99乘法表
  3. IDEA如何将git下来的是工程转为maven工程
  4. asp.net批量下载
  5. _vimrc
  6. QtCreator常用之快捷键
  7. es之主分片和复制分片的交互过程
  8. ubuntu 18.04更换源
  9. mappers:将sql映射注册到全局配置中
  10. easyhook源码分析三——申请钩子