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. juc下Condition类解析

    在使用Lock之前,我们使用的最多的同步方式应该是synchronized关键字来实现同步方式了.配合Object的wait().notify()系列方法可以实现等待/通知模式. Condition接 ...

  3. HarmonyOS三方件开发指南(15)-LoadingView功能介绍

    目录: 1. LoadingView组件功能介绍2. Lottie使用方法3. Lottie开发实现4.<HarmonyOS三方件开发指南>系列文章合集 1. LoadingView组件功 ...

  4. 详解php中函数的引用传递和返回 (附代码)

    本篇文章带大家了解一下php的引用,详细介绍一下函数的引用传递和引用返回.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助.php的引用(就是在变量或者函数.对象等前面加上&符号 ...

  5. Dynamics CRM证书更换

    Dynamics CRM产品一般有两种认证方式.第一种是基于声明的内部访问也就是无证书单纯用账号密码验证.第二种就是联合身份认证,需要安装网站证书. 对于联合身份认证的情况因为需要安装证书,而且证书是 ...

  6. MySQL实战45讲,丁奇带你搞懂

    之前,你大概都是通过搜索别人的经验来解决问题.如果能够理解MySQL的工作原理,那么在遇到问题的时候,是不是就能更快地直戳问题的本质? 以实战中的常见问题为切入点,带你剖析现象背后的本质原因.为你串起 ...

  7. 呵呵,Semaphore,就这?

    这是并发线程工具类的第二篇文章,在第一篇中,我们分析过 CountDownLatch 的相关内容,你可以参考 一文搞懂 CountDownLatch 用法和源码! 那么本篇文章我们继续来和你聊聊并发工 ...

  8. Ray Tracing in one Weekend 阅读笔记

    目录 一.创建Ray类,实现背景 二.加入一个球 三.让球的颜色和其法线信息相关 四.多种形状,多个碰撞体 五.封装相机类 六.抗锯齿 七.漫发射 八.抽象出材料类(编写metal类) 九.介质材料( ...

  9. iview中table多选、加载更多、下载等使用

    记录工作中的点点滴滴,为回忆过往添加片片记忆... 一.Table 1.使用render函数多层渲染以及表格可展开使用 源码地址:https://gitee.com/Mandy_wang/iview- ...

  10. FastAPI项目实战:"异步"接口测试"平台"

    apiAutoTestWeb 是什么? apiAutoTest接口自动化测试工具的可视化版本,将原本对用例的操作转移到Web页面之上 用什么实现? 接口自动化测试:大体上测试逻辑将采用apiAutoT ...