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. GO语言学习笔记4-int与string类型转换

    int与string类型之间相互转换可以借助strconv包里自带的函数实现. 1.string转换成int 函数原型: // base指定进制(2到36),如果base为0,则会从字符串前置判断, ...

  2. 通俗理解vue路由的导航钩子中关于next()

    1 背景:你乘坐汽车从A景区想赶往B景区(模拟路由A跳转到路由B) 1.next() 你乘坐汽车要从A景区到B景区,路过关卡时,守门人拦下你,你量出了next(),守门人一看没问题,赶紧放行,于是你顺 ...

  3. js 创建节点

    //获取对象 console.log(obj)//字符串转对象 var ob = JSON.parse(data); //对象转为字符串 console.log(JSON.stringify(obj) ...

  4. (58)PHP开发

    LAMP 0.使用include和require命令来包含外部PHP文件. 使用include_once命令,但是include和include_once命令相比的不足就是这两个命令并不关心请求的文件 ...

  5. css实现不定宽高的div水平、垂直居中

    一共有三个方案: 1,第一种方案主要使用了css3中transform进行元素偏移,效果非常好 这方法功能很强大,也比较灵活,不仅仅局限在实现居中显示.  兼容方面也一样拿IE来做比较,第二种方法IE ...

  6. linux可用的跨平台C# .net standard2.0 写的高性能socket框架

    能在window(IOCP)/linux(epoll)运行,基于C# .net standard2.0 写的socket框架,可使用于.net Framework/dotnet core程序集,.使用 ...

  7. php curl http digest

    php用curl访问有http digest验证的网址时,不能直接加在URL上,例如: http://user:pass@xxx.xxx.xxx.xxx/index.php?a=1&b=2 这 ...

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

    一.使用Vue.js注意事项 Vue.js在uni-app中使用的差异: 新增:uni-app除了支持Vue实例的生命周期,还支持应用启动.页面显示等生命周期 受限:发布到H5时支持所有vue的语法, ...

  9. python读取文件时遇到非法字符的处理 UnicodeDecodeError: 'gbk' codec can't decode bytes in position

    报错UnicodeDecodeError: 'gbk' codec can't decode bytes in position ipath = 'D:/学习/语料库/SogouC.mini/Samp ...

  10. PHP操作json

    输出json文件中文处理 <?php $json_array = array(); // 1.转换为json字符串(不自动转换为unicode编码) if (version_compare(PH ...