UVa455 Periodic Strings
#include <stdio.h>
#include <string.h>
int main()
{
int T, k, len;
char str[81], *p, *q, *end;
scanf("%d", &T);
while (T--)
{
scanf("%s", str);
len = strlen(str);
end = str+len;
for (k = 1; k < len; ++k)
{
p = str;
q = str + k;
while (p < end && q < end)
{
if (*p != *q)
break;
++p, ++q;
}
if (q == end)
{
q = str;
while (p < end && q < end && *p++ == *q++);
if (p == end)
break;
}
}
printf("%d\n", k);
if (T) putchar('\n');
}
return 0;
}
UVa455 Periodic Strings的更多相关文章
- UVA455 - Periodic Strings(紫书习题3.4)
如果一个字符串可以被某个长度为k的字符串重复多次得到,则称这个字符串的周期为k.例如,字符串"abcabcabcabc"以3为周期(当然,他也以6.12等等为周期). 现在请你编 ...
- UVA.455 Periodic Strings(字符串的最小周期)
Periodic Strings 模板 题意分析 判断字符串的最小周期 代码总览 /* Title:UVA.455 Author:pengwill Date:2016-12-16 */ #includ ...
- 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 OJ 455 Periodic Strings
Periodic Strings A character string is said to have period k if it can be formed by concatenating ...
- 周期串(Periodic Strings,UVa455)
解题思路: 对一个字符串求其最小周期长度,那么,最小周期长度必定是字符串长度的约数,即最小周期长度必定能被字符串长度整除 其次,对于最小周期字符串,每位都能对应其后周期字串的每一位, 即 ABC A ...
- 周期串 (Periodic Strings,UVa455)
#include<stdio.h> #include<string.h> int main(void) { int n,stlen,i,j; ]; while(scanf(&q ...
- 习题3-4 周期串(Periodic Strings, UVa455)
#include<stdio.h> #include<string.h> char s[100]; int main() { int T; scanf("%d&quo ...
- UVa455 Periodic String 的wronganswer问题探讨,以及AC的新思路
题目的意思是一个字符串有某个长度为k的字符串通过不断重复形成的,而k被称为该字符串的周期.而我们所要做的是找出该字符串的最小周期. input The first line is an integer ...
- UVa 455 Periodic Strings
题意:给出一个字符串,找出它的最小的周期,枚举从1到len的周期,看是否满足. #include<iostream> #include<cstdio> #include< ...
随机推荐
- openstack 升级设计要求的指导原则
不知道其他软件有没有类似的指导原则. Theory of Upgrade Grenade works under the following theory of upgrade. New code s ...
- oracle导入导出exp,imp
exp dadifilm/oracle@dg file=/tmp/dadi.dmp full=y imp u_data/321@dg1 file=/dadi_desc.dmp Import: Rel ...
- http-关于application/x-www-form-urlencoded等字符编码的解释说明
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urlen ...
- The "Run One Program Only" Phenomenon
As previously discussed,embedded devices normally embody the functionality they implement.In other w ...
- HDU 4914 Linear recursive sequence(矩阵乘法递推的优化)
题解见X姐的论文 矩阵乘法递推的优化.仅仅是mark一下. .
- javaScript 工作必知(六) delete in instanceof
in in 判断 左边 的字符串或者能转换成字符串的是否属于 右边 的属性. var data = { x: 1, y: 4 };//定义了直接对象 alert("x" in d ...
- HTML系列(五):超链接
<a> 标签定义超链接,最重要的属性是 href 属性,它指示链接的目标.通过将href属性设定不同类型的值可以使链接指向不同类型的链接地址:内部链接.外部链接.锚链接. 内部链接指的是同 ...
- Ubuntu切换至root用户
第一种方式: 使用命令 sudo passwd root 设置root用户的密码 然后su root即可切换至root用户 第二种方式: sudo bash
- English - little,a little,a few,few的区别
few.a few.little.a little的区别和联系: few / a few(形容词)用来修饰可数名词,few表示否定意义,没有,几乎没有, a few表示有肯定意思,有几个. 例如:a ...
- spring mvc 非注解形式
目录(?)[+] webxml配置文件 注如果使用注解可以加上-- servlet上下文配置文件 test-servletxml 实体类Empjava StartController控制器 控制器Em ...