A character string is said to has period K if it can be formed by concatenating one or more repetitions of anoth Er string of length K. For example, the string "abcabcabcabc" had period 3, since it was formed by 4 repetitions of the string "abc ". It also has periods 6 (both repetitions of "abcabc") and (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 would contain a single integer N indicating what many test case which your program would TES T followed by a blank line. Each of the test case would contain a single character string of Non-blank characters. Consecutive input would separated by a blank line.
Output
An integer denoting the smallest period of the input string for each input. The consecutive output is separated by a blank line.
Sample Input
1HoHoHo
Sample Output
2
It's a simple question, but I don't know why I did it all day, probably because I'm not in the state today. At the beginning of the general thought of a thought, but later found that the idea of a lot of errors, after various modifications began a bit of confusion, WA a few times after the note Gaga to find that when the input string is ASDFG such, I understand some deviation, The answer should be 5 instead of 0. The format of the output I did not see two output between a blank line, and later modified several times, or not, grabbed the code of the male to study a bit, changed a way of thinking, but there have been a lot of grammatical errors = Fortunately the last a dropped. Paste the code.
#include <stdio.h>
#include <string.h>
int isloopstring (char str[],int a,int b);
int main ()
{
int n,i,k;
Char str[85];
scanf ("%d", &n);
while (n--)
{
scanf ("%s", str);
for (I=1;i<=strlen (str); i++)
{
if (strlen (str)%i==0)
{
if (isloopstring (Str,i,strlen (str)))
{
K=i;
Break
}
}
}
if (n==0)
printf ("%d\n", K);
Else
printf ("%d\n\n", K);
}
return 0;
}
int isloopstring (char str[],int a,int b)
{
int i,j,flag=1;
for (i=0;i<a;i++)
{
for (J=i+a;j<b;j+=a)
{
if (Str[j]!=str[i])
{
flag=0;
return 0;
}
}
}
if (flag) return 1;
}
D-periodic Strings (UVA-455)