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. JSP入门必读

    JSP基础知识:转自老师上课梳理的笔记,希望对大家有所帮助.有什么不妥当的地方还望大家批评指正. 特别适用于JSP入门的人员使用.1.JSP [1] 简介1.1 HTML    HTML擅长显示一个静 ...

  2. SessionStateMode之SQL Server共享session

    分布式应用首先要解决的是跨域的问题,解决session.frame.cookie的跨域是最基本的,然后才是负载均衡和性能优化,上面的不解决就没法往后面进行.上一博客主要是解决了frame跨域的问题,今 ...

  3. c# typeof 与 GetType 作用与区别

    官方解释: Used to obtain the "System.Type" object for a type. A 'typeof' expression takes the ...

  4. Android学习记录:ViewPager实现欢迎页

    许多APP在第一次启动的时候,都会有welcome page.近日尝试利用ViewPager来实现Welcome Page. d0711 完成记录,跟新下载地址 =================== ...

  5. CCNA基础知识摘录

    cisco设备的启动要点: 1.检测硬件(保存在rom) 2.载入软件(IOS)(保存在Flash) 3.调入配置文件(密码,IP地址,路由协议都保存在此)(此文件保存在NVRAM) 0x2102:正 ...

  6. 团队作业8——第二次项目冲刺(Beta版本)5.24

    1.当天站立式会议照片 会议内容 1.总结前几次会议中出现的问题. 2.对第二天需要做的任务进行分配. 3.询问团队队员任务完成情况以及时间分配是否充分. 4.对今后的任务,发表自己的看法. 2.每个 ...

  7. 201521123103 《Java学习笔记》 第六周学习总结

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

  8. update:我的Emacs配置文件

    ;;设置字体用的  防止中文变成无法识别的框框 (set-default-font "Consolas-11") (set-fontset-font "fontset-d ...

  9. 201521123004 《Java程序设计》第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  10. 201521123080《Java程序设计》第14周学习总结

    本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 书面作业 MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) ...