Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 45008   Accepted: 18794

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

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

Source

#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#define N 1000010
using namespace std;
int next[N];
char str[N];
void getnext(char str[],int next [])
{
next[]=next[]=;
int len=strlen(str);
for(int i=;i<len;i++)
{
// cout<<len<<endl;
int k=next[i];
while(k&&str[i]!=str[k])
{
k=next[k];
//cout<<k<<endl;
}
next[i+]=(str[i]==str[k])?k+:; }
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%s",&str)!=EOF)
{
//cout<<str<<endl;
int m=strlen(str);
if(m==)
break;
getnext(str,next);
// for(int i=0;i<m;i++)
// cout<<next[i]<<" ";
// cout<<endl;
if(m%(m-next[m])==)
printf("%d\n",m/(m-next[m]));
else
puts("");
}
return ;
}

Power Strings(KMP)的更多相关文章

  1. poj2406 Power Strings(kmp)

    poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...

  2. POJ 2406 Power Strings(KMP)

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

  3. 【POJ2406】 Power Strings (KMP)

    Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...

  4. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  5. poj2406 Power Strings(kmp失配函数)

    Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 Descr ...

  6. poj 2406 Power Strings(KMP入门,next函数理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37685   Accepted: 15590 D ...

  7. 「UVA10298」 Power Strings(KMP

    题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 复制 abcd aaaa ababab . 输出样例#1: 复制 1 4 3 题解 Luogu的题解 这里是对目前 ...

  8. poj 2406 Power Strings(kmp求一个串的重复子串)

    题意:重复子串次数 思路:kmp #include<iostream> #include<stdio.h> #include<string.h> using nam ...

  9. 【POJ2406】Power Strings(KMP,后缀数组)

    题意: n<=1000000,cas较大 思路:这是一道论文题 后缀数组已弃疗,强行需要DC3构造,懒得(不会)写 ..]of longint; n,m,i,j,len,ans,st:longi ...

随机推荐

  1. Ubuntu16.04.1上搭建分布式的Redis集群

    为什么要集群: 通常为了,提高网站的响应速度,总是把一些经常用到的数据放到内存中,而不是放到数据库中,Redis是一个很好的Cache工具,当然了还有Memcached,这里只讲Redis.在我们的电 ...

  2. JAVA多线程---ThreadLocal<E>

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px ".SF NS Text" } tips: 1 当前ThreadLocal ...

  3. ViewData 不可以有特殊字符,比如. ,等只允许数字字符和空格

    ViewData 不可以有特殊字符,比如. ,等只允许数字字符和空格

  4. HDU1305 Immediate Decodability(水题字典树)

    巧了,昨天刚刚写了个字典树,手到擒来,233. Problem Description An encoding of a set of symbols is said to be immediatel ...

  5. 演示 Calendar 的一般操作

    package com.yixin.webbrower; /* * 演示 Calendar 的一般操作 */ import java.util.Date; import java.text.Simpl ...

  6. MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等

    drop procedure if exists pro_rep_shadow_rs; delimiter | ---------------------------------- -- rep_sh ...

  7. [置顶] 一个demo学会css

    全栈工程师开发手册 (作者:栾鹏) 一个demo学会css css选择器全解 css操作语法全解 学习了css权威指南这本书,自己喜欢边学边总结边写demo,所以写了这篇文章,包含了大部分的css编程 ...

  8. Android 屏幕相关概念(1)

    1.  术语和概念 术语 说明 备注  Screen size(屏幕尺寸)  指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸  摩托罗拉milestone手机是3. ...

  9. Nhibernate/Hibernate 使用多参数存儲過程 出現could not execute query,Could not locate named parameter等錯誤解決

    <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns=" ...

  10. win10 uwp BadgeLogo 颜色

    本文讲的是在上传应用商店出现BadgeLogo颜色问题,和如何解决,因为我是渣渣,本文可能带有一定的主观性和局限性,说的东西可能不对或者不符合每个人的预期.如果觉得我有讲的不对的,就多多包含,或者直接 ...