UVa 455 - Periodic Strings
来源:互联网 发布:淘宝伴侣手机 编辑:程序博客网 时间:2024/05/18 02:43
https://uva.onlinejudge.org/external/4/455.pdf
455 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
A single character string of up to 80 non-blank characters.
Output
An integer denoting the smallest period of the input string.
Sample Input
HoHoHo
Sample Output
2
分析:
找一个串的最小循环节,数据很弱,暴力枚举就可以
注意输出两组数据间要空一行
#include <iostream>#include <sstream>#include <iomanip>#include <vector>#include <deque>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <bitset>#include <string>#include <numeric>#include <algorithm>#include <functional>#include <iterator>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <cctype>#include <complex>#include <ctime>#define INF 0x3f3f3f3f#define eps 1e-6#define p(x) printf("%d\n", x)#define k(x) printf("Case %d: ", ++x)#define mes(x, d) memset(x, d, sizeof(x))#define s(x) scanf("%d", &x)/*int gcd(int a,int b){ return ! b ? a : gcd(b,a % b);}struct data{ int val; int pos; int ranks;}p[2005];bool cmp1(const data &a,const data &b){ if(a.val == b.val) return a.pos < b.pos; return a.val < b.val;}bool cmp2(const data &a,const data &b){ return a.val > b.val;}bool cmp3(const data &a,const data &b){ return a.pos < b.pos;}*/typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 7;using namespace std;char s[105];int main(){ //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); int T; scanf("%d",&T); while(T--) { scanf("%s",s); int len = strlen(s); for(int i = 1,j;i <= len;i++) { if(len % i == 0) { for(j = i;j < len;j++) if(s[j] != s[j % i]) break; if(j == len) { printf("%d\n",i); break; } } } if(T) puts(""); } return 0;}
- 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-455Periodic 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
- Java学习之多态
- POJ2192(Zipper)
- hdu5130Signal Interference(圆与多边形相交面积模板)
- 多态学习续 抽象类和接口
- Ubuntu更新源 失败
- UVa 455 - Periodic Strings
- cocos2dx——lua自动和手动绑定
- 《Java Concurrency in Practice》中文版笔记
- HDU---1628-Roman Roulette
- PowerDesigner设置表字符编码 utf-8
- NYOJ_75 日期计算 (判断这一天是这一年中的第几天)
- Java I/O 将文件输入到屏幕(控制台)
- 计算GPS两点间的距离的几种算法
- PHP Webservices And C#/.NET SOAP Clients