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

  1. abcd
  2. aaaa
  3. ababab
  4. .

Sample Output

  1. 1
  2. 4
  3. 3
  4.  
  5. 题目分析:给你一个字符串,求出这个字符串的最小循环节的个数,如果该串没有子循环节,就只有自己本身一个循环节,当然结果就是1啦!
    ababab:循环节就是ab,共有3ab; abc:循环节就是abc,只有本身一个。
  6. code
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char s[1000002];
  5.  
  6. int main()
  7. {
  8. int len;
  9. while(scanf("%s", s)!=EOF)
  10. {
  11. if(s[0]=='.') break;
  12. len = strlen(s);
  13. for(int i=1; i<=len; i++)
  14. if(len%i==0)
  15. {
  16. int ok = 1;
  17. for(int j=i; j<len; j++){
  18. if( s[j] != s[j%i] )
  19. {
  20. ok = 0;
  21. break;
  22. }
  23. }
  24. if(ok!=0){
  25. printf("%d\n", len/i);
  26. break;
  27. }
  28. }
  29. }
  30. return 0;
  31. }
  1.  

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. OpenCV学习笔记十四:opencv_objdetect模块

    一,简介: 该库用于目标检测.

  2. POJ1751 Highways

    题目链接    http://poj.org/problem?id=1751 题目大意:输入n:然后给你n个点的坐标(任意两点之间皆可达):输入m:接下来m行每行输入两个整数x,y表示 点x与点y 已 ...

  3. 【BZOJ5047】空间传送装置 最短路

    [BZOJ5047]空间传送装置 Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参数a_i,b_i,c_i,d_i来描述 ...

  4. node.js 关于跨域和传递给前台参数

    /*为app添加中间件处理跨域请求*/ app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin& ...

  5. window.XMLHttpRequest对象详解

    来自:http://blog.csdn.net/lccone/article/details/7743946 window.XMLHttpRequest XMLHttpRequest对象是当今所有AJ ...

  6. Java中Jedis操作Redis与Spring的整合

    Redis是一个key-value存储系统.它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集合).这些数据类型都支持push/pop. ...

  7. linux 服务器所支持的最大句柄数调高数倍(与服务器的内存数量相关)

    https://github.com/alibaba/p3c/blob/master/阿里巴巴Java开发手册(详尽版).pdf 2. [推荐]调大服务器所支持的最大文件句柄数(File Descri ...

  8. String研究

    =======================String=================================== String里的==和equalsJava String “equal ...

  9. hdu 2112 HDU Today(map与dijkstra的结合使用)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. windows server2003/2008中权限账户

    在windows server 2003与windows server 2008 R2中,查看文件夹权限时,尤其是用cacls命令查看时,经常会见nt authority system这样的用户信息. ...