Power Strings
2015-08-07 15:56
204 查看
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 37439 | Accepted: 15467 |
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. 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.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
唉,太气人了,数组刚开始开小了。开成char a[1000000];应该再大一些。
[code]
#include<stdio.h> #include<string.h> char a[1000100]; //int len; char p[1000100]; int kmp() { int i,j,len; i=0,j=-1; p[0]=-1; len=strlen(a); while(i<len) { if(j==-1||a[i]==a[j]) { i++;j++; //printf("%d ",j); p[i]=j; } else j=p[j]; // printf("%d\n",j); } i=len-j; if(len%i==0) { return len/i; } return 1; } int main() { int c; while(scanf("%s",a)&&a[0]!='.') { c=kmp(); printf("%d\n",c); } return 0; }
[/code]
相关文章推荐
- hdoj 1686 Oulipo【kmp】
- 两段函数求值
- 数据结构基础(24) --红黑树的设计与实现(下)
- html笔记05:html、css、javascript综合案例
- Redis 键值数据类型及基本操作
- 如何中断线程?
- KMP算法 —— next 数组的应用 --- 前缀中最小循环节,最大重复次数
- 值得一看的博客
- 设置HttpSendRequest阻塞时间
- 堆排序算法
- 需要这样一个记事本-15 ReportViewer打印默认页边距、页面方向问题
- 浅析JVM
- POJ1149 PIGS (最大流)
- 大数据专家Bernard Marr:大数据是如何对抗癌症的?
- Devexpress Report Service 使用方法
- (四) Basic Build Customization(基本的构建定制 :签名,构建,混淆)
- A1062 Talent and Virtue (25)
- 数据结构基础(23) --红黑树的设计与实现(中)
- requireJS使用
- (绝对有用)iOS获取UUID,并使用keychain存储