UVa OJ 455 Periodic Strings
| 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的更多相关文章
- 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 ...
- UVA.455 Periodic Strings(字符串的最小周期)
Periodic Strings 模板 题意分析 判断字符串的最小周期 代码总览 /* Title:UVA.455 Author:pengwill Date:2016-12-16 */ #includ ...
- UVa 455 Periodic Strings
题意:给出一个字符串,找出它的最小的周期,枚举从1到len的周期,看是否满足. #include<iostream> #include<cstdio> #include< ...
- UVa 455 - Periodic Strings - ( C++ ) - 解题报告
1.题目大意 求一个长度不超过80的字符串的最小周期. 2.思路 非常简单,基本就是根据周期的定义做出来的,几乎不需要过脑. 3.应该注意的地方 (1) 最后输出的方式要注意,不然很容易就PE了.不过 ...
- 【习题 3-4 UVA - 455】Periodic Strings
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举 [代码] #include <bits/stdc++.h> using namespace std; const ...
- Periodic Strings UVA - 455
A character string is said to have period k if it can be formed by concatenating one or more repet ...
- UVA 10679 I love Strings!!!(AC自己主动机)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- LeetCode OJ:Isomorphic Strings(同构字符串)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- LeetCode OJ:Multiply Strings (字符串乘法)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
随机推荐
- ECMAScript 2017(ES8)新特性简介
目录 简介 Async函数 共享内存和原子操作 Object的新方法 String的新方法 逗号可以添加到函数的参数列表后面了 简介 ES8是ECMA协会在2017年6月发行的一个版本,因为是ECMA ...
- c++反汇编 switch
switch 线性处理 24: int nIndex = 0; 01377EBE C7 45 F8 00 00 00 00 mov dword ptr [nIndex],0 25: scanf(&qu ...
- MyBatis、Spring、SpringMVC 源码下载地址
MyBatis.Spring.SpringMVC 源码下载地址 github mybatis https://github.com/fengyu415/MyBatis-Learn.git spring ...
- Java程序员都要懂得知识点:反射
摘要:Java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为java语 ...
- 前端 | vxe-table 翻页保留复选框状态
0 前言 在前端开发过程中时常会遇到表格相关的显示与处理.组件库通常都会提供表格组件,对于展示.简单操作这些常用功能通常也够用:但如果需要更多的定制或进行比较复杂的操作,组件库自带的组件可能会捉襟见肘 ...
- Java中的泛型 - 细节篇
前言 大家好啊,我是汤圆,今天给大家带来的是<Java中的泛型 - 细节篇>,希望对大家有帮助,谢谢 细心的观众朋友们可能发现了,现在的标题不再是入门篇,而是各种详细篇,细节篇: 是因为之 ...
- 【CTF】Pwn入门 XCTF 部分writeup
碎碎念 咕咕咕了好久的Pwn,临时抱佛脚入门一下. 先安利之前看的一个 Reverse+Pwn 讲解视频 讲的还是很不错的,建议耐心看完 另外感觉Reverse和Pwn都好难!! 不,CTF好难!! ...
- 解决Echarts+<el-tab-pane>的警告:Can't get DOM width or height
1 问题描述 环境: Chrome 87 Element-Plus Vue3.0.5 <el-tab>+<el-tab-pane>中使用Echarts 警告如下: 2 代码 & ...
- BPF for storage:一种受外核启发的反式
BPF for storage:一种受外核启发的反式 译自:BPF for storage: an exokernel-inspired approach BPF主要用于报文处理,通过绕过网络栈提高报 ...
- Blade模板引擎教程-常用语法格式
打印变量或者默认值,这个语法会自动转义变量内容中的html标记,使得html标签原样输出Welcome, {{ $name or 'California' }} 打印变量原始内容,不进行转义的用法{! ...