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;
}

Period_JAVA相关推荐

最新文章

  1. Pygame:编写一个小游戏
  2. swift 可变參数
  3. 一种全新的点击率建模方案
  4. MSP430F5529 DriverLib 库函数学习笔记(七)定时器B
  5. 关于C# DataGridView 全选与取消的小问题
  6. android白圈闪现动画,Android基于Shader的图像处理(9)-仿抖音闪白特效
  7. 中考计算机表格操作题,中考信息技术Excel操作题.xls
  8. springboot系列(十八):如何Windows安装redis?你玩过么|超级详细,建议收藏
  9. LM2596S-ADJ DC-DC降压芯片使用
  10. aria2最新tracker服务器,【无灯+Hiboy】padavan下自动更新aria2的BT tracker 服务器列表...
  11. 佛系前端面试题记录--第四周
  12. maven环境变量配置以及集成到Eclipse中
  13. 基于canvas+uniapp的9宫格拼图游戏组件
  14. 用 8550 和 ULN2003 驱动小型直流电机正反转
  15. 分享苹果电脑和乔布斯的十项成功秘诀
  16. DllPlugin动态链接库插件
  17. 星淘惠:四川一地获批设立跨境电子商务综合试验区跨境电商再添新砖
  18. Devign: Effective Vulnerability Identification byLearning Comprehensive Program Semantics viaGraph
  19. ansible部署和基本的操作
  20. 我们是如何测试360手机浏览器的 –360手机浏览器测试范围概述

热门文章

  1. 修改jupyter的保存位置
  2. android源码出现的@字符意义总结
  3. qconbeijing2014
  4. 【沟通交流】弱关系向强关系的转变
  5. 从重采样到数据合成:如何处理机器学习中的不平衡分类问题?
  6. 区块链研习 | 区块链里所说的“智能合约”是什么? 本文作者:敖萌 编辑:温晓桦 2017-10-11 20:31 导语:谈到区块链,必然离不开“智能合约”这个词。我们在本系列的第一篇文章中提到“智能
  7. 京东金融曹鹏:没有数据的金融科技公司是纸上谈兵
  8. 灰度图像--图像增强 锐化基础
  9. jvm性能调优实战 - 42JVM性能优化思路Review
  10. 爬虫学习笔记(十三)—— scrapy-redis(二):存储到MySQL、Scrapy项目部署