Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 38038   Accepted: 15740

Description

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

Input

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s you should print the largest n such that s = a^n for some string a.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
3 题目分析:给你一个字符串,求出这个字符串的最小循环节的个数,如果该串没有子循环节,就只有自己本身一个循环节,当然结果就是1啦!
像ababab:循环节就是ab,共有3个ab; 像abc:循环节就是abc,只有本身一个。 code:
#include <stdio.h>
#include <string.h> char s[1000002]; int main()
{
int len;
while(scanf("%s", s)!=EOF)
{
if(s[0]=='.') break;
len = strlen(s);
for(int i=1; i<=len; i++)
if(len%i==0)
{
int ok = 1;
for(int j=i; j<len; j++){
if( s[j] != s[j%i] )
{
ok = 0;
break;
}
}
if(ok!=0){
printf("%d\n", len/i);
break;
}
}
}
return 0;
}


poj 2406 Power Strings【字符串+最小循环节的个数】的更多相关文章

  1. POJ 2406 Power Strings next数组循环节应用、

    题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的 ...

  2. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

  3. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  4. hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)

    传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...

  5. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

  6. KMP + 求最小循环节 --- POJ 2406 Power Strings

    Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...

  7. POJ 2406 - Power Strings - [KMP求最小循环节]

    题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...

  8. 【kmp+最小循环节】poj 2406 Power Strings

    http://poj.org/problem?id=2406 [题意] 给定字符串s,s=a^n,a是s的子串,求n最大是多少 [思路] kmp中的next数组求最小循环节的应用 例如 ababab ...

  9. KMP解决字符串最小循环节相关问题

    经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个 ...

随机推荐

  1. es6 async与await实战

    在使用js的时候,我们经常会遇到一个问题,就是我们需要等待请求返回再做下一步处理,之前的处理方式是通过ajax的success或者callback之类的方法,不过一层一层真的恶心,而且只是针对单个页面 ...

  2. 编写自己的ls命令

    ····要编写ls命令,首先要了解它能做什么,完成了什么工作,是如何完成这些工作的····  一.ls命令能做什么? 我们在命令行输入ls,ls默认找出当前目录中所有文件的文件名,并且按照字典序排序后 ...

  3. python多线程/多进程

    thread和threading的区别 threading相对与thread是更高级别的线程管理模块 thread和threading模块中的一些属性会有冲突 thread模块拥有的同步原因实际上只有 ...

  4. StartCom免费ssl证书申请以及在Tomcat环境中的配置

    提示:建议以下操作不使用谷歌浏览器(该网站的证书不识别...),可以看到我的截图中谷歌换成了ie(没装火狐)...建议该申请使用火狐 前面介绍了下自签名的ssl证书,虽然可以实现https协议访问,但 ...

  5. Machine Learning - week 2 - 编程练习

      3. % J = COMPUTECOST(X, y, theta) computes the cost of using theta as the % parameter for linear r ...

  6. js的简单的逻辑算法题

    比如题目:寻找1~1000之内,所有能被5整除.或者能被6整除的数字 1 for(var i = 1 ; i <= 1000 ; i++){ 2  if(i % 5 == 0 || i % 6 ...

  7. Testlink安装:Notice:Undefined index: type in C:\inetpub\wwwroot\testlink-1.9.3\install\installCheck.php on line 41

    问题现象:

  8. C#数组实践

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cont ...

  9. C#数组学习

    1.多维数组 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespa ...

  10. GCE 创建一个Linux VM

    sudo yum install wget 安装Java sudo wget --no-check-certificate --no-cookies --header "Cookie: or ...