UVa455 Periodic Strings(周期串)

原创 2015年11月20日 00:30:44

Description

A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string "abcabcabcabc" has period 3, since it is formed by 4 repetitions of the string "abc". It also has periods 6 (two repetitions of "abcabc") and 12 (one repetition of "abcabcabcabc").

Write a program to read a character string and determine its smallest period.

Input

The first line oif the input file will contain a single integer N indicating how many test case that your program will test followed by a blank line. Each test case will contain a single character string of up to 80 non-blank characters. Two consecutive input will separated by a blank line.

Output

An integer denoting the smallest period of the input string for each input. Two consecutive output are separated by a blank line.

Sample Input

1

HoHoHo

Sample Output

2

代码如下:

思路:假设周期为i,从周期i=1开始逐渐试探。

博客已搬:洪学林博客

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

周期串(Periodic Strings,UVa455)

最近在学习开始学习算法,现在看的是刘汝佳的《算法竞赛入门》,感觉还是有必要把一些有问题题目记录下来。另外其他的代码都同步到了gitbub上的仓库了,可能不是最好的,不过都被在uva上ac了。欢迎感兴趣...

UVA 455 - Periodic Strings

A character string is said to have period k if it can be formed by concatenating one or more repetit...

uva455 Periodic Strings & hdu3746 Cyclic Nacklace

两道题类似,uva455是求最小周期,hdu3746是求最少插入多少字符可以使得字符串最少有两个周期。 类似于kmp算法,使用一个next数组, 对字符串进行处理,标记所有的前缀, 时间复杂度是O(n...

UVA455 Periodic Strings

Description A character string is said to have period k if it can be formed by concatenating one ...

UVa 455 - Periodic Strings

455 - Periodic Strings

UVA 455 Periodic Strings

Periodic Strings Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu S...

UVa 455 Periodic Strings

Description Download as PDF Periodic Strings A character string is said to have period k if it ...

UVa 1584 Circular Sequence / 455 Periodic Strings(枚举字符串)

原题地址https://vjudge.net/problem/UVA-1584 题意:DNA的四个字母CGAT排列成环形,可以移动起点,输出字典序最小的环形序列(顺时针)。 解题思路这道题是《算法...

UVa 455 Periodic Strings (字符串处理)

455 - Periodic Strings Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlin...

【UVa】[455]Periodic Strings

我已经感受到了 紫书习题满满的恶意
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)