Power Strings

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 1791   Accepted: 528

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.

Output

For each s you should print the largest n such that s = a^n for some string a. 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.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
3

思路:由于题目要求的是最大值,因此从n开始向下查找,第一次出现的满足条件的那个数就是最大的,查找就可以结束,如果查找到1是仍未找到合适的值,则为1,就是说不是任何字符串的次方如abcd

#include<stdio.h>
#include<string.h>
#define N 1000001
int str_judge(int n,int i,char * pstr)
{
int j,k,p = 0;
if(n%i==0)
{

for(j = 0;j<n-i;j++)
{
if(*(pstr+j)==*(pstr+j+i))
p = 1;
else
return 0;
}
return p;
}
else
return 0;
}

int main()
{
int counter,k,len_str;
char str[N]={'0'};
while(strcmp(str,".")!=0)
{
counter = 0;
scanf("%s",str);
getchar();
len_str = strlen(str);
for(k = 1;k<len_str;k++)
{
if(str_judge(len_str,k,str)==1)
{
printf("%d\n",len_str/k);
counter++;
break;
}
}
if(counter==0&&strcmp(str,".")!=0)
printf("%d\n",1);
}
}

Power Strings的更多相关文章

  1. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  2. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

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

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

  4. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...

  5. E - Power Strings,求最小周期串

    E - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  6. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

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

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

  8. 【POJ2406】 Power Strings (KMP)

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

  9. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

随机推荐

  1. java三大特性性:封装、继承和多态

    一.封装 封装是指隐藏对象的属性及实现细节,对外仅提供接口可见.封装实现了信息隐藏,利于软件复用.其优点是达到了模块化的标准,从而提高了代码的复用程度.在某种程度上,封装也大大改善了软件开发的可维护性 ...

  2. ZOJ 1025 Wooden Sticks(快排+贪心)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木 ...

  3. Chi Square Distance

    The chi squared distance d(x,y) is, as you already know, a distance between two histograms x=[x_1,.. ...

  4. STL:remove和erase区别

    C++ STL中的remove和erase函数曾经让我迷惑,同样都是删除,两者有什么区别呢? vector中的remove的作用是将等于value的元素放到vector的尾部,但并不减少vector的 ...

  5. 专题二、ArrayList序列化技术细节详解

    一.绪论 所谓的JAVA序列化与反序列化,序列化就是将JAVA 对象以一种的形式保持,比如存放到硬盘,或是用于传输.反序列化是序列化的一个逆过程. JAVA规定被序列化的对象必须实现java.io.S ...

  6. ECMA中关于if与else的关系的一句英文,感觉比较经典

    Each else for which the choice of assocated if is ambiguous shall be associated with the nearest pos ...

  7. div+css3实现漂亮的多彩标签云,鼠标移动会有动画

    div+css3实现漂亮的多彩标签云,鼠标移动会有动画 点击运行效果 <style> .dict { margin: 20px 0;clear:both ;text-align:left; ...

  8. 【 java版坦克大战--事件处理】 坦克动起来了

    折腾了这么久,坦克总算能动了.只贴代码编辑不给上首页,花了半个小时的时间写了n多注释. 再顺便把绘图的原理发在这里: 绘图原理 Component类提供了两个和绘图有关的重要方法: ①   paint ...

  9. C语言结构体中的函数指针

      这篇文章简单的叙述一下函数指针在结构体中的应用,为后面的一系列文章打下基础 本文地址:http://www.cnblogs.com/archimedes/p/function-pointer-in ...

  10. (转载)在状态栏即时显示Hint

    在状态栏即时显示Hint(所有窗口,包括子窗口控件的hint) 在主窗体中放入一个ApplicationEvents控件.添加如下代码.其中Items[***]中的***代表状态栏的各个子panel, ...