Power Strings
来源:互联网 发布:淘宝有国际版 编辑:程序博客网 时间:2024/05/22 23:40
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).
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.
For each s you should print the largest n such that s = a^n for some string a.
abcdaaaaababab.
143
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
让求字符串的最小循环节有几个
#include<stdio.h>#include<math.h>#include<string.h>#include<iostream>#include<algorithm>const int maxn=1e6+10;char s[maxn];int Next[maxn];void getNext(){ int i=0; int j=-1; int l=strlen(s); while(i<l) { if(j==-1||s[i]==s[j]) { i++; j++; Next[i]=j; } else j=Next[j]; }}int main(){ while(~scanf("%s",s)) { int l=strlen(s); if(s[0]=='.') break; Next[0]=-1; getNext(); int ans=l-Next[l];//最小循环节长度。 if(l%ans!=0)//串不是由最小循环节构成 printf("1\n"); else printf("%d\n",l/ans); }}
阅读全文
0 0
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- 数字5个
- QT按钮被触发两次的问题
- Fresco三级缓存
- 数据库存储BloB格式图片,并从数据库中取出显示到页面中
- ccf-2016121-中间数
- Power Strings
- 解决:DButils QueryRunner count(*) JavaBean里封装的结果集 返回null 或者返回 0
- MVP详解
- Location对象
- Tensorflow载入数据的三种方式
- C语言-求三个数中的最大值
- c语言学习——字符数组与字符串的使用详解
- JSP指令,动作标签,内置对象
- SSL2520 2014年汕头市选拔赛普级组 小球(math)