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. html-----010

    22 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  2. VS2010修改默认配置路径

    视图->属性管理器 弹出如下截图:

  3. C++多态性的理解

    本文章转载来自:http://www.sollyu.com/?p=627 代码 #include <iostream.h> class Animal { public: void eat( ...

  4. oracle所在磁盘空间不足导致了数据库异常

    oracle所在磁盘空间不足导致了数据库异常.需要减小数据文件的大小来解决. 1.检查数据文件的名称和编号 select file#,name from v$datafile; 2.看哪个数据文件所占 ...

  5. jquery 插件的编写

    /** * 插件的学习 * 原文地址:http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html#home */ ;(function($, ...

  6. jQuery选择器(一)

    1.#id根据给定的ID匹配一个元素. <div id="notMe"><p>id="notMe"</p></div& ...

  7. PHP程序实现利用rand(1,100)函数产生10个1~100之间的随机数

    //echo rand(1,100);$max=0;$min=100;for($i=0;$i<=9;$i++){ $rand[$i]=rand(1,100); if($rand[$i]>$ ...

  8. js 遍历json对象

    //方法一: var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13} ...

  9. 分享自己动手弄的基于Rime的新世纪五笔输入法码表

    实验室新搞了一台iMac,没有支持新世纪的码表的中文输入法啊.搜索半天大家推荐用Rime(鼠须管)来挂接新世纪码表.不知道还有没有其它支持外挂码表的Mac版输入法,暂时只有搞这个了.看了一下别人已经做 ...

  10. pyes-elasticsearch的python客户端使用笔记

    elasticsearch入门:  http://www.qwolf.com/?p=1387 一.重要的概念 http://834945712.iteye.com/blog/1915432 这篇文章很 ...