FZU 1901 Period II
来源:互联网 发布:锐捷网络招聘 编辑:程序博客网 时间:2024/05/21 09:15
Problem 1901 Period II
Accept: 225 Submit: 584
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
For each prefix with length P of a given string S,if
S[i]=S[i+P] for i in [0..SIZE(S)-p-1],
then the prefix is a “period” of S. We want to all the periodic prefixs.
Input
Input contains multiple cases.
The first line contains an integer T representing the number of cases. Then following T cases.
Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.
Output
For each test case, first output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of periodic prefixs.Then output the lengths of the periodic prefixs in ascending order.
Sample Input
4
ooo
acmacmacmacmacma
fzufzufzuf
stostootssto
Sample Output
Case #1: 31 2 3
Case #2: 63 6 9 12 15 16
Case #3: 43 6 9 10
Case #4: 29 12
Source
FOJ有奖月赛-2010年05月#include <cstdio>#include <cstring>const int N = 1000010;int next[N];char str[N];void get_next() {int i = 0, j = -1;next[i] = j;while (str[i]) {if (j == -1 || str[i] == str[j])next[++i] = ++j;elsej = next[j];}}int main() {int T, cnt = 0;scanf("%d", &T);while (T--) {scanf("%s", str);get_next();int len = strlen(str);int i = len, ans = 0;while (i) {ans++;i = next[i];}printf("Case #%d: %d\n", ++cnt, ans);i = next[len];while (i) {printf("%d ", len - i);i = next[i];}printf("%d\n", len);}return 0;}
0 0
- fzu 1901 Period II
- FZU 1901 Period II
- FZU 1901 Period II
- FZU 1901 Period II
- FZU 1901Period II
- fzu 1901 Period II(KMP)
- FZU Problem 1901 Period II
- FZU 1901 Period II (KMP)
- fzu 1901 Period II (KMP)
- FZU 题目1901 Period II (KMP)
- FZU 1901 Period II (kmp)
- FZU 1901 Period II (KMP+技巧)
- FZU 1901 Period II(KMP)
- FZU - 1901 Period II(KMP next数组的理解)
- fzuProblem 1901 Period II
- FZU1901 Period II
- FZU 1603 Checkers II
- FZU 1888三角形问题II
- tomcat远程调试
- GDB 支持多线程调试
- Dukto 文件传输软件(推荐)
- Maven常用插件
- 关于oracle plsql数据库ORA-01480: STR 绑定值的结尾 Null 字符缺失 的问题解决办法。
- FZU 1901 Period II
- [Android]最省内存的ViewPager添加小圆点指示器
- Machine Learning读书会,面试算法讲座,创业活动,算法班(15年6月)
- css续集
- Qt工具类
- IOS 应用内购买(In-App Purchase)之开发
- Wireless LCD Monitor
- sql server 不能远程连接
- ios开发系列之Core Graphics中的CGContext