1237
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
A single character string of up to 80 non-blank characters.
Output
An integer denoting the smallest period of the input string.
Sample Input
HoHoHoSample Output
2代码:
#include<stdio.h>
#include<string.h>
int main(){
char str[80];
int len,period,j;
while(scanf("%s",str)!=EOF) {
period=1;
len = strlen(str);
while(period!=len) {
if(len%period!=0) {
period++;
continue;
}
for(j=period;j<len;j++) {
if(str[j]!=str[j%period])
break;
}
if(j==len) {
printf("%d\n",period);
break;
}
period++;
}
if(period==len) {
printf("%d\n",period);
}
}
return 0;
}
分享到:
相关推荐
【标题】"joj acm 部分习题解答"揭示了这是一份与JOJ(Judge Online Job)和ACM(国际大学生程序设计竞赛)相关的资源,主要是作者对于某些题目的解题思路和代码实现。JOJ是用于在线评测编程竞赛题目的一种平台,而...
如果是单一的源代码文件,那么它可能解决了JOJ平台上的1237号问题或者与"acm"相关的某个特定问题。 总结这些知识点,我们可以得出以下要点: 1. ACM编程竞赛:这是一种国际性的算法竞赛,培养学生的编程和解决问题...
【标题】:“JOJ上做的一些ACM试题” 在计算机科学领域,ACM(Association for Computing Machinery)国际大学生程序设计竞赛是一项备受瞩目的比赛,旨在提升大学生的算法设计、问题解决以及团队协作能力。JOJ...
【标题】"JOJ-jilin-university--acm.rar_joj" 提供的是吉林大学JOJ在线判题系统的编程竞赛代码集,主要用于帮助初学者入门。 【描述】中的信息表明,这个压缩包内的代码样例是专门为在JOJ平台上进行编程训练的学生...
#### 标题:吉林大学ACM题集.pdf—JOJ 此文档标题明确指出了文档的主要内容——一个由吉林大学组织编写的ACM竞赛题集,并且该题集是以PDF格式提供的。这里提到的“JOJ”即吉林大学在线裁判系统(Jilin University On...
joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考
根据给定的信息,本文将详细解释“acm joj 1600”中的两种大数取模运算方法。此问题主要关注如何高效地计算形如 \(a^b \mod m\) 的表达式,这对于处理大数据或进行密码学运算非常重要。 ### 大数取模运算 #### ...
吉林大学 joj 1000-2645题代码,嘿嘿,大家就不用在花JPOINT买代码了,祝ACMer实现自己的心愿