周期串Uva455 P37 3-4
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的更多相关文章
- E - Power Strings,求最小周期串
E - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1358 (所有前缀中的周期串) Period
题意: 给出一个字符串,在所有长度大于1的前缀中,求所有的周期至少为2的周期串,并输出一个周期的长度以及周期的次数. 分析: 有了上一题 HDU 3746 的铺垫,这道题就很容易解决了 把next求出 ...
- 【周期串】NYOJ-1121 周期串
[题目链接:NYOJ-1121] 例如:abcabcabc 该字符串的长度为9,那么周期串的长度len只可能为{1,3,9},否则就不可能构成周期串. 接下来,就是要在各周期间进行比较.描述不清... ...
- 51Nod1553 周期串查询 字符串 哈希 线段树
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1553.html 题目传送门 - 51Nod1553 题意 有一个串只包含数字字符.串的长度为n,下标 ...
- 问题 K: 周期串plus
问题 K: 周期串plus 时间限制: 1 Sec 内存限制: 128 MB提交: 682 解决: 237[提交] [状态] [命题人:外部导入] 题目描述 如果一个字符串可以由某个长度为k的字符 ...
- 周期串(JAVA语言)
package 第三章习题; /* * 如果一个字符可以由某个长度为k的字符串重复多次得到,则称该串以k为周期. * 例如:abcabcabcabc 以3为周期(注意:它也以6和12为周期) * ...
- 周期串(Periodic Strings,UVa455)
解题思路: 对一个字符串求其最小周期长度,那么,最小周期长度必定是字符串长度的约数,即最小周期长度必定能被字符串长度整除 其次,对于最小周期字符串,每位都能对应其后周期字串的每一位, 即 ABC A ...
- UVa455 最小周期串问题
A character string is said to have period k if it can be formed by concatenating one or more repetit ...
- 习题3-4 周期串(Periodic Strings, UVa455)
#include<stdio.h> #include<string.h> char s[100]; int main() { int T; scanf("%d&quo ...
随机推荐
- PHP正则使用技巧1
$pattern="/<div class=\"cover g-playicon\">(.*?)>/s"; 意思为抓取<div clas ...
- kubernetes 强制删除istio-system空间,强制删除pod
加上这个选项 --grace-period=0 --force--grace-period=0 --force 先删除deployment,pod,svc再删除namespace > kubec ...
- BZOJ 1084 (SCOI 2005) 最大子矩阵
1084: [SCOI2005]最大子矩阵 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3560 Solved: 1779 [Submit][Sta ...
- 现金贷平台下载量TOP100 涉逾30家P2P
一.什么是现金贷,现状如何 那么什么是现金贷呢?在笔者看来,狭义的现金贷主要是指基于互联网等技术手段的小额现金贷款,广义的现金贷可以包括任何以小额现金和存款为标的进行借贷的行为,是一种无担保.无抵押. ...
- PostgreSQL 优势,MySQL 数据库自身的特性并不十分丰富,触发器和存储过程的支持较弱,Greenplum、AWS 的 Redshift 等都是基于 PostgreSQL 开发的
PostgreSQL 优势 2016-10-20 21:36 686人阅读 评论(0) 收藏 举报 分类: MYSQL数据库(5) PostgreSQL 是一个自由的对象-关系数据库服务器(数据库 ...
- ssm下使用分页插件PageHelper进行分页
1. 导入maven依赖: <dependency> <groupId>com.github.pagehelper</groupId> <artifactId ...
- HDFS under replicated blocks
under replicated blocks 解决: 找出没有复制的block: hdfs fsck / | grep 'Under replicated' | awk -F':' '{print ...
- 2019-11-9-win10-支持默认把触摸提升-Pointer-消息
title author date CreateTime categories win10 支持默认把触摸提升 Pointer 消息 lindexi 2019-11-09 15:32:31 +0800 ...
- 2019-8-31-dotnet-core-发布只带必要的依赖文件
title author date CreateTime categories dotnet core 发布只带必要的依赖文件 lindexi 2019-08-31 16:55:58 +0800 20 ...
- 查看java资源的占用
1,使用命令top -p <pid> ,显示你的java进程的内存情况,pid是你的java进程号,比如1232,按H,获取每个线程的内存情况3,找到内存和cpu占用最高的线程pid,比如 ...