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. android自定义View_2——Making the View Interactive

    前言:绘制出一个view只是自定义view的一个部分,还需要自定义一些view的行为,来反馈用户的使用操作,反馈的 行为要合理性,就像真是的物理世界一样,不要太玄幻哦. 可以将view的行为封装到in ...

  2. 更新mac系统和更新到Xcode7.3版本出现的: cannot create __weak reference in file using manual reference counting

    之前的编程没有遇到过,应该是苹果官方那边又做了新规吧. 不过不要紧,只要根据这个就能解决报错问题.  Set Build Settings -> Apple LLVM 7.1 - Languag ...

  3. idea 全部报错找不到包

    解决报错方法如下:

  4. mybatis 一次执行多条SQL MySql+Mybatis+Druid之SqlException:sql injection violation, multi-statement not allow

    如果用JDBC jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=utf8 ...

  5. selenium-webdriver 中执行js代码

    #获取标签的text文本值 js1="return document.getElementById('key1').innerText" dr.execute_script(js1 ...

  6. Kotlin——中级篇(五):枚举类(Enum)、接口类(Interface)详解

    在上一章节中,详细的类(class)做了一个实例讲解,提到了类(class)的实例化.构造函数.声明.实现方式.和Java中类的区别等.但是对于Kotlin中的类的使用还远远不止那些.并且在上文中提到 ...

  7. 宇视4G设备采用GB/T28181协议成功接入EasyGBS国标流媒体平台的设置流程

    经过了多天的调试对接,终于将宇视的布控球顺利接入到了EasyGBS的国标平台,特地写一下对接过程中遇到的问题,希望能帮助大家避开一些麻烦: 第一步:电脑连接无线网络IPCWIFI,密码12345678 ...

  8. 通过margin负值去除padding

    .pay-type { // 图片布局前通过margin负值去除padding margin: 0 -@page-padding-horizontal; display: inline-flex; } ...

  9. Git is fundamentally a content-addressable filesystem with a VCS user interface written on top of it

    w “加一层去解决问题”:计算机解决问题的思路.怎样将其应用到代码中呢?比如亚马逊接口的开发. git加一UI层去实现易用性和降低用户的迁移成本. https://git-scm.com/book/e ...

  10. Delphi中的dll操作

    利用delphi dll wizard进行dll的编写. 创建:保存时改dll名称 library test2; uses SysUtils, Classes, forms, dialogs; {$R ...