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 ...
随机推荐
- 如何讓Android系統顯示CJK擴展區漢字
由於一些特殊需要,需要在個人設備上顯示CJK擴展區漢字,經多方詢問並驗證,找到了一下辦法,暫總結如下. 一.電腦上顯示 在電腦(Windows,Linux,Mac等系統)上可以通過安裝「花園明朝字體」 ...
- 利用Xlinix SDK 建立Linux程序以及对该程序进行调试
一.创建Linux程序 1. 点击File > New > Application Project .并参照下图设置. 2. 输入工程名,并选择存储路径. 3. 选择所需的操作系统平台(O ...
- MySQL的多实例
一.准备工作 1.关闭mysql进程 # pkill # service mysqld stop 2.从系统服务中删除mysqld # chkconfi ...
- tp_shop解读1
由于想弄一个商城,因此研究了一下tp_shop,这个据说能完成几乎所有的功能. 考虑到原有的例子过于复杂,因此把所有相关的数据都删除了,结果上来就出错了,查了两天,大致弄清楚了状况. 关于错误的原因 ...
- 比较全面的gdb调试命令
from:http://blog.csdn.net/xiajun07061225/article/details/8960332 http://blog.csdn.net/cjfeii/article ...
- Google Web Designer 测试
这东东完全就是一个flash啊,简单测试,感觉就是个做HTML5动画的..不过暂时是beta版的, 官方安装版的半天打不开,这边有个绿色版的,需要的童鞋可以这里下载:百度网盘
- 尝试使用Java6API读取java代码
主要类:JavaCompiler FileManager JavaCompiler .CompilationTaskAbstractProcessor参考代码https://today.java.n ...
- mac 生成支付宝的rsa公钥和私钥 php版本
openssl genrsa -out rsa_private_key.pem 1024 公钥 openssl rsa -in rsa_private_key.pem -pubout -out rsa ...
- php类的方法
方法就是在类中的function,很多时候我们分不清方法与函数有什么差别,在面向过程的程序设计中function叫做函数,在面向对象中function则被称之为方法. 同属性一样,类的方法也具有pub ...
- yii2单个视图加载jss,css
1,定义资源:首先在AppAsset.php里面定义2个方法, //按需加载css public static function addCss($view, $cssfile) { $view-> ...