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. 新建Application 报错android.app.Application cannot be cast

    我在开发APP的时候重新使用了一个类,继承了android.app.Application.但是在运行的时候提示java.lang.ClassCastException: android.app.Ap ...

  2. Linux 添加时间

    添加在指令后面 `date +%Y%m%d%H%M`注意date和+之间一定要有空格 ps: %%    一个文字的 %  %a    当前locale 的星期名缩写(例如: 日,代表星期日)  %A ...

  3. SpringBoot_03_SpringBoot对其他技术的整合

    1.SpringBoot整合Mybatis 1.2 添加Mybatis的起步依赖 <!--mybatis起步依赖--> <dependency> <groupId> ...

  4. sql数据库还原,出现媒体簇的结构不正确,SQLServer无法处理此媒体簇的解决方法

    问题: sql数据库还原,出现媒体簇的结构不正确,SQL Server无法处理此媒体簇. 异常如下图. 造成问题的原因: 我的电脑上安装了sql2005和sql2008,问题就在于我用sql2008的 ...

  5. JAVA 文件的上传下载

    一.上传文件 1.使用 transferTo 上传 @ResponseBody @RequestMapping(value = "/file/upload") public Res ...

  6. iOS疑问

    1.__NSFrozenDictionaryM在数组类簇中是什么角色?

  7. day22_5-xml模块

    # 参考资料:# python模块(转自Yuan先生) - 狂奔__蜗牛 - 博客园# https://www.cnblogs.com/guojintao/articles/9070485.html ...

  8. STM32 STM32F4 寄存器怎么配置不上, 无法往寄存器写入数据

    当出现这个问题时,往往是因为你没有在RCC寄存器中把相关的时钟使能打开. 配置寄存器之前记得调用"RCC_AxxxPeriphClockCmd"先打开需要配置的时钟源,别调用了“R ...

  9. Cefsharp实现快捷键功能

    原文:Cefsharp实现快捷键功能 1 . 实现IKeyboardHandler接口 public class KeyBoardHander : IKeyboardHandler { public ...

  10. EasyNetQ异常处理

    代码下载 https://download.csdn.net/download/u010312811/11252093 官方Demo https://github.com/EasyNetQ/EasyN ...