多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Power Strings(POJ2406)(KMP)

Power Strings(POJ2406)(KMP)

來源:程序員人生   發布時間:2014-12-15 09:05:07 閱讀次數:2724次
Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 33623   Accepted: 13966

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

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

Source

Waterloo local 2002.07.01
KMP,next表示模式串如果第i位(設str[0]為第0位)與文本串
第j位不匹配則要回到第next[i]位繼續與文本串第j位匹配。
則模式串第1位到next[n]與模式串第n-next[n]位到n位是匹配的。
如果n%(n-next[n])==0,則存在重復連續子串,長度為n-next[n]。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int next[1000002]; char s[1000002]; int len; int get_next(char *s) { int i=0,j=⑴; next[0]=⑴; while(i<len) { if(j==⑴||s[i]==s[j]) { i++; j++; next[i]=j; } else j=next[j]; } if(len%(len-next[len])==0) return len/(len-next[len]); else return 1; } int main() { while(gets(s)!=NULL) { if(s[0]=='.') break; len=strlen(s); printf("%d ",get_next(s)); } return 0; }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产毛片a级 | 中文字幕乱码无限2021丫丫 | 91亚洲欧美综合高清在线 | 一区二区三区高清 | 国产精品爱久久久久久久小 | 91伊人久久大香线蕉 | 国产精品所毛片视频 | 波多野结衣一级视频 | 国产一区二区三区在线 | 欧美性xxxx交 | 看一级毛片国产一级毛片 | 视频在线观看免费 | 亚洲成人福利 | 亚洲性另类| 亚洲精品久久久久久久久久久网站 | 福利在线免费观看 | 亚洲精品一区亚洲精品 | 亚洲视频中文字幕在线观看 | 国产精品jizz在线观看软件 | www.在线免费观看 | 欧美性猛片xxxxⅹ免费 | 成人男女网免费 | 经典三级一区二区三区视频 | 69视频在线 | 一级欧美一级日韩 | 亚洲成a人片在线观看尤物 亚洲成a人片在线观看中文!!! | 色综合网站在线 | 久久精品国产99久久无毒不卡 | 精品在线视频播放 | 久久精品视频7 | freesex呦交孩 | 欧美大陆日韩 | 天天狠狠 | 中文字幕亚洲第一 | 在线中文字幕亚洲 | 欧美xxxx免费 | 免费精品美女久久久久久久久久 | 中文字幕视频一区二区 | 日本在线一区 | 天天躁夜夜燥2021 | 国产日韩欧美高清 |