程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> poj 2406 Power Strings

poj 2406 Power Strings

編輯:C++入門知識

poj 2406 Power Strings


Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33636 Accepted: 13973

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

題目大意:給出一個字符串,求這個串是有幾個子串構成的 思路:用KMP算法中的next數組,這個字符串的next數組裡邊,字符串的總長度減去最後一個字符所對應的next值就是子串的長度 具體為什麼,應該是next數組的值是根據這個字符串本身,用一定規則得出的,這個真的好巧妙的說,kmp算法,好好看看。 2014,12,5

#include
#include
char x[1100000];
int next[1100000];
void getnext(char s[]){
	int len1,i,j;
	len1=strlen(s);
	i=0;j=-1;
	next[i]=j;
	while(i

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved