UVA 455 Periodic Strings(字符串的循环节)
来源:互联网 发布:中国f1车队知乎 编辑:程序博客网 时间:2024/05/22 17:48
UVA 455 Periodic Strings
A character stringis said to have periodk if it can be formed by concatenating one or morerepetitions of anotherstring of lengthk. For example, the string”abcabcabcabc” has period 3, since it is formed by 4 repetitionsof the string ”abc”. Italso has periods 6 (tworepetitions of ”abcabc”) and 12 (one repetition of ”abcabcabcabc”).
Write a program to read a character stringand determine its smallest period.
Input
The first lineoif the inputfile will contain a single integer N indicating how many test casethat your program will test followed by a blank line. Each test case will containa single characterstring of up to 80 non-blank characters.Two consecutive input will separated by a blankline.
Output
An integerdenoting the smallest period of the inputstring for each input.Two consecutive output are separated by a blank line.
Sample Input
1
HoHoHo
Sample Output
2
题意:
输出字符串的最小循环节
思路:
卡的是输出格式,应该是字符串的处理问题。
AC CODE:
#include<stdio.h>#include<cstring>#include<algorithm>#define HardBoy main()#define ForMyLove return 0;using namespace std;const int MYDD = 1103;int HardBoy {int n, kc = 0;scanf("%d", &n);while(n--) {getchar();char cv[MYDD];scanf("%s", cv);int lencv = strlen(cv);for(int i = 1; i <= lencv; i++) {if(lencv % i == 0) {/*当前长度被整除才可能为循环节*/int flag = 1;for(int j = i; j < lencv; j++) {if(cv[j] != cv[j%i]) {flag = 0;/*前面若为循环节,依次判断后面的*/break;}}if(flag) {printf("%d\n", i);break;}}}if(n)printf("\n");/*输出的格式调整*/}ForMyLove}/*61231231231233*/
- UVA 455 Periodic Strings(字符串的循环节)
- UVa 455 - Periodic Strings(字符串处理)
- UVa 455 Periodic Strings(周期字符串)
- UVA.455 Periodic Strings(字符串的最小周期)
- UVa 455 - Periodic Strings【字符串】
- UVa 1584 Circular Sequence / 455 Periodic Strings(枚举字符串)
- UVa 455 Periodic Strings (字符串处理)
- UVa 455 Periodic Strings 【字符串求周期】
- UVA 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 - Periodic Strings
- UVa 455 Periodic Strings
- UVa - 455 Periodic Strings
- UVa 455 Periodic Strings
- UVa 455 - Periodic Strings
- Uva 455-periodic strings
- Uva 455-periodic strings
- JDK1.5--)很重要的特性——泛型
- http协议学习
- 算法总结(一) 算法分析
- Java基础 (==和equals)
- 小朋友排队
- UVA 455 Periodic Strings(字符串的循环节)
- 多个dubbo配置中心
- Hadoop平台分析之最高效的英文单词学习顺序
- 深度学习中构造自己的图像数据集格式
- PySide简介
- Wolf and Rabbit
- centos 7编译hadoop 2.7.3
- linux下多线程之pthread_detach(pthread_self())
- jQuery初步学习