Power Strings
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的更多相关文章
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- POJ 2406 Power Strings
F - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- E - Power Strings,求最小周期串
E - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- poj 2406 Power Strings kmp算法
点击打开链接 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27368 Accepted: ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- 【POJ2406】 Power Strings (KMP)
Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...
- poj 2406 Power Strings【最小循环节】
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36926 Accepted: 15254 D ...
随机推荐
- $.extend(),与$.fn.extend() 讲解
$.extend(),与$.fn.extend() 讲解(一) (2013-07-11 10:24:31) 转载▼ 转自:http://blog.sina.com.cn/s/blog_a3bd3bd0 ...
- IOS 学习笔记 2015-03-20 OC-集合-数组
[NSArray] 一 定义 1 不可变数组 2 oc中数组的元素可以是任何对象 3 数字中装有元素的地址 二 初始化 NSArray *变量 = [[NSArry alloc] initWithOb ...
- 将数据库二进制图片导出显示到EPPlus Excel2007中
1.EPPlus Excel 控件可以参考我的另一篇博客:http://blog.163.com/pei_huiping/blog/static/206573067201281810549984/ 这 ...
- VS2015 C#.net4.6 windows的定时服务
1.创建项目 C#->经典桌面->windows服务 2.创建定时服务 找到服务1,自动生成了 OnStart(服务开启时运行),OnStop(服务关闭时运行)两个函数,我们需要在开启时新 ...
- juery mobile select下来菜单选项提交form问题
注意: data-native-menu="false" 虽然具有渲染作用,但是无法进行js提交. <script type="text/javascript&q ...
- Linux使用问答
1.ubuntu 查看安装的软件包? 在终端输入 sudo dpkg -l http://vardesa.blog.hexun.com/58593247_d.html 其他:http://qiuye. ...
- c#开发Mongo笔记第一篇
现在开发的这个项目要用mongo数据库开发,发现网上的这方面教程还是比较少的,只能边看官方说明边进行开发,再开发过程中写下笔记,也算上是一个总结吧. 我开发使用的是vs2013了,驱动用的是最新的1. ...
- EXCEL : We can't do that to a merged cell.
- PHP练习题(二)
程序6.题目: 假设某人有100,000现金,每经过一次路口需要进行一次交费交费规则为当他现金大于50,000时每次需要交%5,如果现金小于等于50,000时每次交5,000.问此人可以经过多少次这个 ...
- JS实现精确加减乘除
说明:项目中要使用 JS 实现自动计算的功能,进行一些浮点数运算时,计算结果却是一长串的值,这里提供一个解决方法,问题基本上可以解决. 具体代码如下: //加法函数 function accAdd(a ...