UVA455「Periodic Strings」
1. 题目
题目链接:UVA455「Periodic Strings」 。
Description
A character string is said to have period if it can be formed by concatenating one or more repetitions of another string of length . For example, the string abcabcabcabc
has period , since it is formed by repetitions of the string abc
. It also has periods (two repetitions of abcabc
) and (one repetition of abcabcabcabc
).
Write a program to read a character string and determine its smallest period.
Input
The first line of the input file will contain a single integer 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 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 |
|
Sample Output
1 |
|
2. 题解
分析
字符串前缀函数的应用水题,结束。
代码
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!