FOJ Problem 1011 Power Strings

Problem Description

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

Each test case is a line of input representing s, a string of printable characters. For each s you should print the largest n such that s = a^n for some string a. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
 
//求最小周期串,得出最小周期串的总个数 
# include "stdio.h"
# include "string.h" 
char a[1000100];
int main()
{
	int i, j, k;
	int length;
	int flage;
	while(scanf("%s", a))
	{
		if(a[0]=='.')
		{
			break;
		}
		length=strlen(a);
		for(i=1; i<=length; i++)//枚举周期串长度
		{
			if(length%i==0)
			{
				flage=1;
				for(k=i; k<=length-1; k++)
				{
					if(a[k%i]!=a[k])
					{
						flage=0;
						break;
					}
				}
				if(flage)
				{
					printf("%d\n", length/i);
					break;
				}
			}
		} 
	}
	return 0;
}



 
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页