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. asp.net 2.0里也可以用JSON的使用方法

    本人找到一份,可以在asp.net2.0里实现JSON方式传送数据的方法.但是原方法,不能在数据中带有{.}.[.]."等,所以我做特意做了转意. 全部代码如下. /// <summa ...

  2. C++ RTTI的应用

    先看下方的代码,我们所处的context在<<< void* pX = (void*)pGiven; >>>处,只知道上面这些类的信息和pX指针,怎么判断pX指向对 ...

  3. Laravel创建Route

    <?php /* |-------------------------------------------------------------------------- | Routes Fil ...

  4. CentOS 7.0 防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙.firewall:systemctl start firewalld.service#启动firewalls ...

  5. httpclient 怎么带上登录成功后返回的cookie值访问下一页面

    我是只很菜很菜的小鸟.刚上班,有这个一个需求.要我抓取别的网站的数据.     我根据用户密码登录一个网站成功后,生成一个cookie值.我已经获取到了.然后要带上这个cookie值进行下一页面的访问 ...

  6. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.6——签署发布apk

    问题: 为了将APK发布到google市场,需要对APK数字签名. 解决方案: 可以使用java的keytoll命令去创建一个证书,并且在gradle配置文件的signingConfigs块使用. 讨 ...

  7. SharePoint 离线安装

    SharePoint 离线安装,主要是AppFrabic服务出错,可以使用下来命令: "X:\WindowsServerAppFabricSetup_x64.exe" /i Cac ...

  8. 《从零开始学Swift》学习笔记(Day 33)——属性观察者

    原创文章,欢迎转载.转载请注明:关东升的博客 为了监听属性的变化,Swift提供了属性观察者.属性观察者能够监听存储属性的变化,即便变化前后的值相同,它们也能监听到. 属性观察者主要有以下两个: l ...

  9. EasyNVR depends on ffmpeg,yasm/nasm not found or too old. Use --disable-yasm for a crippledbuild

    安装ffmpeg过程中,执行./configure时,报yasm/nasm not found or too old. Use --disable-yasm for a crippledbuild错误 ...

  10. Java 科学计数法

    目录 Java 科学计数法 1 科学计数法的概念 1.1 有效数字 1.2 E记号 2 Java中的科学计数法 2.1 NumberFormat 2.2 DecimalFormat 2.3 BigDe ...