算法竞赛入门经典 第三章 uVA455 - Periodic Strings
来源:互联网 发布:java set和get的用法 编辑:程序博客网 时间:2024/05/20 14:44
Periodic Strings
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
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
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){int n;while (scanf("%d", &n) != EOF){char str[1000];for (int i = 0; i < n; i++){scanf("%s", str);int len = strlen(str);for (int j = 1, k; j <= len; j++){if (len%j == 0){for (k = j; k < len; k++){if (str[k] != str[k%j])break;}if (k == len){printf("%d\n", j);break;}}}if (i != n - 1)printf("\n");}}return 0;}
0 0
- 算法竞赛入门经典 第三章 uVA455 - Periodic Strings
- 《算法竞赛入门经典2ndEdition 》习题3-4 周期串(Periodic Strings, Uva455)
- 算法竞赛入门经典-习题3-4 周期串(Periodic Strings, UVa455)
- 算法竞赛入门经典(第二版) 习题3-4 周期串(Periodic Strigs) UVa455
- 算法竞赛入门经典3.5 谜题UVa455
- 算法竞赛入门经典 UVa455周期串
- 算法竞赛入门经典(第2版)习题3-4 周期串 Periodic Strings UVa445
- UVa455 - Periodic Strings
- UVA455 - Periodic Strings
- uva455 Periodic Strings
- Periodic Strings UVA455
- UVA455 Periodic Strings
- uva455 - Periodic Strings
- Periodic Strings Uva455 【KMP】
- [UVA455]Periodic Strings
- UVa455 Periodic Strings
- UVa455--Periodic Strings
- UVA455 Periodic Strings
- jQuery 之父:每天写代码
- 现今的三大分词算法介绍
- 数据结构(6)堆排序
- 黑马程序员_java_IO流
- 深度学习中梯度下降知识准备
- 算法竞赛入门经典 第三章 uVA455 - Periodic Strings
- Android Studio与Eclipse SDK无法更新解决方案
- LRU Cache
- OC-NSNumber
- HDU2561(排序)
- 唉!不要乱用函数哦,特别是你不熟悉的!
- Android开发之旅:环境搭建及HelloWorld
- php无限级分类并把末级产品展示出来的思路
- 让程序崩溃后生成Core Dump