日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Period_JAVA

發(fā)布時(shí)間:2025/3/21 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Period_JAVA 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Description
For each prefix of a given string S with N characters (each character has an
ASCII code between 97 and 126, inclusive), we want to know whether the prefix
is a periodic string. That is, for each i (2 ≤ i ≤ N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as AK ,
that is A concatenated K times, for some string A. Of course, we also want to
know the period K.

Input
The input file consists of several test cases. Each test case consists of two
lines. The first one contains N (2 <= N <= 1 000 000) – the size of the string S.
The second line contains the string S. The input file ends with a line, having the
number zero on it.

Output
For each test case, output “Test case #” and the consecutive test case
number on a single line; then, for each prefix with length i that has a period K >
1, output the prefix size i and the period K separated by a single space; the
prefix sizes must be in increasing order. Print a blank line after each test case.

Sample
Input

3

aaa

12

aabaabaabaab

0

Output

Test case #1

2 2

3 3

Test case #2

2 2

6 2

9 3

12 4

Hint

#include<bits/stdc++.h>using namespace std;char s[1000010]; int Next[1000010];void get_next() {memset(Next, 0, sizeof(Next));int i = 0;int j = -1;Next[0] = -1;int len = strlen(s);while(i < len){if(j == -1 || s[i] == s[j]){Next[++i] = ++j;if((i % (i - Next[i]) == 0) && (i / (i - Next[i]) > 1))printf("%d %d\n", i, i / (i - Next[i]));}elsej = Next[j];} } int main() {int n;int cnt = 0;while(~scanf("%d", &n) && n != 0){cnt++;scanf("%s", s);printf("Test case #%d\n", cnt);get_next();printf("\n");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Period_JAVA的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。