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

最开始以为是求出现次数最小的那个字符;

后来想一想是真的不对;

然后看着数据不大, 就用暴力枚举的方法;

求出最小的周期,那么就是从最小的开始枚举,也就是长度为1, 再judge;

 #include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x)) #define LL long long using namespace std; const int INF = 0x3f3f3f3f; const int maxn = ; char str[]; char s[]; int main() { int T; cin >> T; while(T--) { clr(str); cin >> str; int len = strlen(str); for(int i = ; i < len; i++) { if(len % (i+) != ) continue; int cnt = , flag = ; clr(s); for(int j = ; j <= i; j++ ) { s[cnt++] = str[j]; } //puts(s); int tmp = i + ; for(int k = ; k < len / (i + ) - ; k++) { for(int l = ; l < cnt; l++) { //printf("%c %c\n", s[l], str[tmp]); if(s[l] != str[tmp++]) { flag = ; break; } } } if(flag) { cout << i + << endl; if(T) cout << endl; break; } //puts("_________"); } } return ; }

周期串Uva455 P37 3-4的更多相关文章

  1. E - Power Strings,求最小周期串

    E - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  2. HDU 1358 (所有前缀中的周期串) Period

    题意: 给出一个字符串,在所有长度大于1的前缀中,求所有的周期至少为2的周期串,并输出一个周期的长度以及周期的次数. 分析: 有了上一题 HDU 3746 的铺垫,这道题就很容易解决了 把next求出 ...

  3. 【周期串】NYOJ-1121 周期串

    [题目链接:NYOJ-1121] 例如:abcabcabc 该字符串的长度为9,那么周期串的长度len只可能为{1,3,9},否则就不可能构成周期串. 接下来,就是要在各周期间进行比较.描述不清... ...

  4. 51Nod1553 周期串查询 字符串 哈希 线段树

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1553.html 题目传送门 - 51Nod1553 题意 有一个串只包含数字字符.串的长度为n,下标 ...

  5. 问题 K: 周期串plus

    问题 K: 周期串plus 时间限制: 1 Sec  内存限制: 128 MB提交: 682  解决: 237[提交] [状态] [命题人:外部导入] 题目描述 如果一个字符串可以由某个长度为k的字符 ...

  6. 周期串(JAVA语言)

    package 第三章习题; /*  * 如果一个字符可以由某个长度为k的字符串重复多次得到,则称该串以k为周期.  * 例如:abcabcabcabc 以3为周期(注意:它也以6和12为周期)  * ...

  7. 周期串(Periodic Strings,UVa455)

    解题思路: 对一个字符串求其最小周期长度,那么,最小周期长度必定是字符串长度的约数,即最小周期长度必定能被字符串长度整除 其次,对于最小周期字符串,每位都能对应其后周期字串的每一位, 即 ABC  A ...

  8. UVa455 最小周期串问题

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

  9. 习题3-4 周期串(Periodic Strings, UVa455)

    #include<stdio.h> #include<string.h> char s[100]; int main() { int T; scanf("%d&quo ...

随机推荐

  1. Codeforces 553E Kyoya and Train

    题目大意 链接:CF533E 给一张\(n\)个点,\(m\)条边的图,起点\(1\)终点\(n\),如果不能在\(T\)的时间内到达则需支付\(X\)的代价. 走每条边都会支付一定代价,经过一条边\ ...

  2. sublime text-----查看当前文件的编码格式

    1.preferences->settings,在user中添加 "show_encoding": true, "show_line_endings": ...

  3. C++和JavaScript脚本的相互调用

    脚本调用C++相对比较容易,使用ATL组件只需要抛双接口即可,但在exe里如何做到呢?本文实现了在exe里脚本和C++的相互调用.在EXE里也需要对外抛送一个继承自IDispatch的接口.并需要重载 ...

  4. timestamp的自动更新 ON UPDATE CURRENT_TIMESTAMP

    最近有一个关于MySQL版本升级的事,涉及到一些关于时间类型的细节问题需要查明,因此到官网找到相关文章,翻出来比较方便自己理解,博客这里也贴一下. 参考官网网址: https://dev.mysql. ...

  5. LightOJ-1007-Mathematically Hard-欧拉函数打表+前缀和+预处理

    Mathematically some problems look hard. But with the help of the computer, some problems can be easi ...

  6. maven配置步骤

    仅做操作手册使用,一些操作频率较高的步骤已省略 第一步:度娘下载maven并解压 此处使用了apache-maven-3.2.5-bin.zip, 解压后复制到了D盘的D:\maven\apache- ...

  7. Git合并时遇到冲突或错误后取消合并

    当合并分支时遇到错误或者冲突,分支旁边会多出“|MERGING”这个东西 有这个状态存在时,会导致后面想要再合并的时候提示如下 所以需要先取消这次合并,使用“git merge --abort”命令

  8. SpringCloud学习笔记《---04 Hystrix---》基础篇

  9. 【模板篇】splay(填坑)+模板题(普通平衡树)

    划着划着水一不小心NOIP还考的凑合了… 所以退役的打算要稍微搁置一下了… 要准备准备省选了…. 但是自己已经啥也不会了… 所以只能重新拾起来… 从splay开始吧… splay我以前扔了个板子来着, ...

  10. T2960 全民健身【思维Dp,预处理,差分优化】

    Online Judge:YCJSOI Label:Dp,思维题,预处理,滚动优化 题目描述 乐乐现在掌管一个大公司,办公楼共有n层.为了增加员工的身体素质,他决定在每层楼都建立一个活动室,活动室分乒 ...