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. Web里URL空格的转换方法

    今天收到一个Bug修复的任务,Bug为在页面上输入一个文件夹名包含空格,点击该文件夹的URL后链接错误. 看URL是HttpUtility.UrlEncode将空格转换成了“+”号,原因找到就着手解决 ...

  2. (转)初步认识拓展UnityEditor编辑器定制

    初步认识拓展UnityEditor编辑器定制 热度 9529 2015-9-4 18:50 |个人分类:Unity3d| 编辑器, 拓展 我相信无数初学者看别人游戏都经常看到他们的Inspector中 ...

  3. eclipse 解决编译出现GBK或UTF8 编码错误的方法

    eclipse由于开源所以支持了比较杂的编码方式,而这些一个工程导入时添加了不少的外来程序,由于不是同一工程一次编码带来了其中含有GBK和 UTF8   UTF16  ASCII等文件编译时就会出现错 ...

  4. 一些常用的html css整理--文本长度截取

    div+css设置列表div超出部分显示...(单行文本) width:200px; //指定宽度: overflow:hidden; //将超出内容隐藏 text-overflow:ellipsis ...

  5. HDOJ 4549 M斐波那契数列 费马小定理+矩阵高速幂

    MF( i ) = a ^ fib( i-1 ) * b ^ fib ( i )   ( i>=3) mod 1000000007 是质数 , 依据费马小定理  a^phi( p ) = 1 ( ...

  6. Linux C 获取系统时间信息

    比如获取当前年份:               /* 获取当前系统时间 暂时不使用 ; ; time_t now; struct tm *timenow; time(&now); timeno ...

  7. py 与 pyc 文件

    本文要说明的问题 pyc 文件是什么 pyc 文件的作用 py 与 pyc 文件冲突 pyc 文件是什么 当 py 文件加载后,py 文件被二进制编码成 pyc 文件.py 文件的修改时间被记录到 p ...

  8. Introduction to Mathematical Thinking - Week 2

    基本数学概念 real number(实数):是有理数和无理数的总称 有理数:可以表达为两个整数比的数(a/b, b!=0) 无理数是指除有理数以外的实数 imply -- 推导出 不需要 A 能推导 ...

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

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

  10. C语言结构体数组内带字符数组初始化和赋值

    1.首先定义结构体数组: typedef struct BleAndTspRmtCmd{ char terminal[3]; char note[3]; char rmtCmd[10]; char c ...