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

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
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
int kases;
char s[100];
scanf("%d",&kases);
while (kases--)
{
scanf("%s",s);
int length = strlen(s);
for (int i = 1; i <= length; i++)
{ if (length%i == 0)
{
bool ok = true;
for (int j = i; j < length; j++)
if (s[j] != s[j%i])
{
ok = false;
break;
}
if (ok)
{
printf("%d\n",i);
break;
}
}
}
if (kases != 0)
printf("\n");
}
return 0;
}

本题没有难度,但由于没有认真审题,忽略了相邻两个输出之间要有空白行,提交了几次,认真审题是关键啊。

UVa OJ 455 Periodic Strings的更多相关文章

  1. UVa 455 - Periodic Strings解题报告

    UVa OJ 455 Periodic Strings A character string is said to have period k if it can be formed by conca ...

  2. UVA.455 Periodic Strings(字符串的最小周期)

    Periodic Strings 模板 题意分析 判断字符串的最小周期 代码总览 /* Title:UVA.455 Author:pengwill Date:2016-12-16 */ #includ ...

  3. UVa 455 Periodic Strings

    题意:给出一个字符串,找出它的最小的周期,枚举从1到len的周期,看是否满足. #include<iostream> #include<cstdio> #include< ...

  4. UVa 455 - Periodic Strings - ( C++ ) - 解题报告

    1.题目大意 求一个长度不超过80的字符串的最小周期. 2.思路 非常简单,基本就是根据周期的定义做出来的,几乎不需要过脑. 3.应该注意的地方 (1) 最后输出的方式要注意,不然很容易就PE了.不过 ...

  5. 【习题 3-4 UVA - 455】Periodic Strings

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举 [代码] #include <bits/stdc++.h> using namespace std; const ...

  6. Periodic Strings UVA - 455

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

  7. UVA 10679 I love Strings!!!(AC自己主动机)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. LeetCode OJ:Isomorphic Strings(同构字符串)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  9. LeetCode OJ:Multiply Strings (字符串乘法)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

随机推荐

  1. 【LeetCode】52. N-Queens II(位运算)

    [题意] 输出N皇后问题的解法个数. [题解] 解法一:传统dfs回溯,模拟Q放置的位置即可,应该不难,虽然能通过,但是时间复杂度很高. 解法二:位运算大法好! 首先要明白这道题里两个核心的位运算 1 ...

  2. Redis实战篇(三)基于HyperLogLog实现UV统计功能

    如果现在要开发一个功能: 统计APP或网页的一个页面,每天有多少用户点击进入的次数.同一个用户的反复点击进入记为 1 次,也就是统计 UV 数据. 让你来开发这个统计模块,你会如何实现? 如果统计 P ...

  3. CSS 文字装饰 text-decoration & text-emphasis

    在 CSS 中,文字算是我们天天会打交道的一大类了,有了文字,则必不可少一些文字装饰. 本文将讲讲两个比较新的文字装饰的概念 text-decoration 与 text-emphasis,在最后,还 ...

  4. 详解CURL状态码,最全的代码列表

    curl是一个强大的命令,其中我们经常使用的通过curl 加地址和端口号,判断目标链接状态,下面列出了curl 返回的状态码. 举例: [root@k8s-master1 ~]# curl k8s-m ...

  5. [图论]最短路径问题 :Floyed-Warshall

    最短路径问题 目录 最短路径问题 Description Input Output Sample Input Sample Output 解析 了解Floyed算法 Floyed算法的核心思想: 代码 ...

  6. 答应我,别在go项目中用init()了

    前言 go的 init函数给人的感觉怪怪的,我想不明白聪明的 google团队为何要设计出这么一个"鸡肋"的机制.实际编码中,我主张尽量不要使用init函数. 首先来看看 init ...

  7. Recoil 中多级数据联动及数据重置的合理做法

    前情回顾 书接上回,前面引出了在数据存在级联的情况下,各下拉框之间的默认值及值变化的处理.简单回顾一下: 场景是: 地域下拉决定可选的可用区 默认选中第一个地域,通过设置 atom 的 default ...

  8. --系统编程-网络-tcp客户端服务器编程模型、socket、htons、inet_ntop等各API详解、使用telnet测试基本服务器功能

    PART1 基础知识 1. 字节序 网络字节序是大端字节序(低地址存放更高位的字节), 所以,对于字节序为小端的机器需要收发网络数据的场景,要对这些数据进行字节序转换. 字节序转换函数,常用的有四个: ...

  9. Python基础(十四):while循环与break、continue关键字

    前面我们已经学习了for循环,今天再带着大家讲述一下while循环.那么for循环和while循环,到底有什么区别呢? Python中for循环和while循环本质上是没有区别的,但是在实际应用上,针 ...

  10. python基础(〇):注释

    单行注释 Python中单行注释以 # 开头,例如: # 这是一个注释1 print("Hello, World!") # 这是一个注释2 多行注释 单引号(''') ''' 这是 ...