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. JavaScript - 常用对象相关

    1. String对象 length : 字符串的长度 charAt(index) : 返回指定位置的字符串, 下标从0开始 indexOf(str) : 返回指定的字符串在当前字符串中首次出现的位置 ...

  2. LOIC Download

    { //https://github.com/NewEraCracker/LOIC }

  3. Windows del

    删除一个或数个文件. DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] namesERASE [/P] [/F] [/S] [/Q] [/A[[:]attribu ...

  4. 单层感知机_线性神经网络_BP神经网络

    单层感知机 单层感知机基础总结很详细的博客 关于单层感知机的视频 最终y=t,说明经过训练预测值和真实值一致.下面图是sign函数 根据感知机规则实现的上述题目的代码 import numpy as ...

  5. 出现不不能引java.util.Date包的情况

    出现不不能引java.util.Date包的情况 那个时间段不能引,IDE的bug,等一会儿就好了 心得:很多时候没必要和bug死磕,因为真的不是你的问题.

  6. PAT甲级——A1138 Postorder Traversa【25】

    Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and in ...

  7. final、static、package、import,和内部类、代码块总结

    final: final是最终修饰符,可以修饰类.成员方法.变量 final修饰的类无法被继承 final修饰的方法无法被重写 final修饰的变量无法被再次赋值,变为了常量 final修饰的引用数据 ...

  8. 第三周课堂笔记1thand2thand3th

    元组   元组是以逗号隔开的 元组有索引有切片,元组是小括号和中括号的集合, 元组中的东西不可修改(小括号内的东西不可被修改,但是小括号里的列表和字典可以被修改)   2. 由内存地址来分 可变数据类 ...

  9. 18-4-bind

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Linux操作系统系列-Linux发布Web项目

    安装JDK 下载jdk 验证是否安装JDK java 如果已经安装了jdk查看已经安装的版本 java -version 如果安装不是所需要的 卸载当前java SDK 通过rpm查看已经安装包 (r ...