Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 29402   Accepted: 12296

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 两种做法:
 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[];
int t;
int main()
{
char x;
while()
{
t=;
x=getchar();
if(x=='.')break;
while()
{
a[t++]=x;
if(x=='\n')break;
x=getchar();
}
int p=,k=;
t--;
for(int i=; i<t; i++)
{
if(a[i]==a[i%p])
k++;
else
{
if(p==k)k++;
p=k;
}
}
if(t%p==)
printf("%d\n",t/p);
else printf("1\n");
}
}
 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[];
int t,next[];
void fun()
{
next[]=;
int i,j=;
for(i=;i<t;i++)
{
while(j>&&a[i]!=a[j])j=next[j-];
if(a[i]==a[j])j++;
next[i]=j;
}
}
int main()
{
char x;
while()
{
t=;
x=getchar();
if(x=='.')break;
while()
{
a[t++]=x;
if(x=='\n')break;
x=getchar();
}
t--;
fun();
if(t%(t-next[t-])==)
printf("%d\n",t/(t-next[t-]));
else printf("1\n");
}
}

Power Strings poj2406(神代码)的更多相关文章

  1. Power Strings[poj2406]题解

    Power Strings Description - Given two strings a and b we define ab to be their concatenation. For ex ...

  2. Power Strings POJ2406 KMP 求最小循环节

    相比一般KMP,构建next数组需要多循环一次,因为next[j]代表前j-1个字符的最长相同前缀后缀,比如字符串为aab aab aab共9个字符,则next[10]等于前9个字符中最长相同前缀后缀 ...

  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. POJ2406 Power Strings —— KMP or 后缀数组 最小循环节

    题目链接:https://vjudge.net/problem/POJ-2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Tot ...

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

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

  6. poj2406 Power Strings(kmp)

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

  7. poj2406 Power Strings (kmp 求最小循环字串)

    Power Strings   Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 47748   Accepted: 19902 ...

  8. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

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

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

随机推荐

  1. css 找到隐藏元素个数

    <form>   <input type="hidden" name="email" />   <input type=" ...

  2. 【转载】js常用方法和片段

    在网上看了不少js方法的总结没,自己也尝试总结过,这篇只迄今为止觉得最清楚的,尤其是call和apply的方法总结,很到位!! 1.javascript删除元素节点 IE中有这样一个方法:remove ...

  3. Eslint配置

    //ESLint 4.5.0,参考了eslint官方以及alloyteam团队配置 module.exports = { parser: 'babel-eslint', parserOptions: ...

  4. 关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx.xml]

    关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx ...

  5. 吐槽下微软的vs code编辑器

    缺点:不能同时打开多个文件夹(打开多个文件夹得先ctrl+shift+N窗口或者除非你的所有项目文件都在同一个文件夹目录下) 优点是支持用户设置以及提供很多插件 // 将设置放入此文件中以覆盖默认设置 ...

  6. centos6 内核优化

     以下为部分优化参数,具体优化方法还要看情况而定 [root@localhost ~]# vi /etc/sysctl.conf    #末尾添加如下参数 net.ipv4.tcp_syncookie ...

  7. 团队作业8----第二次项目冲刺(beta阶段)5.22

    Day4-05.22 1.每日会议 会议内容: 1.帮助新成员进一步了解项目. 2.陈鑫龙说明昨日任务的完成情况. 3.组长林乔桦安排今日的任务. 讨论照片: 2.任务分配情况: 每个人的工作分配表: ...

  8. 201521123048《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 1.clone方法 1.1 Object对 ...

  9. 201521123037 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 接口: 接口简而言之是方法声明和常量值的集合,接口中所有的方法默认为public ...

  10. Ubuntu下PHP MySQL环境搭建-upcoming-ChinaUnix博客

    编程语言选择php5 , web服务器选择Apache2 ,后台数据库选择MySQL首先安装编译工具, 打开终端 sudo apt-get install build-essential autoco ...