UVA

//周期串 uva455
//借鉴了代码思路: http://blog.csdn.net/mobius_strip/article/details/40584263
/*收获:
**1.暴力破解,但要注意,不是死列举,而是发现,循环节首先必定是长度的因子,再去暴力破解,不要蛮解
**2.注意格式的控制
*/
#include <bits/stdc++.h>
using namespace std;
char a[100];
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		cin >> a;
		int len = strlen(a);
		
		for (int i = 1, j; i <= len; i++)
		{
			if (len % i) continue;
			for (j = i; j < len; j++)
			if (a[j] != a[j % i])
			break;
			
			if (j == len)
			{
				cout << i << endl;
				break;
			}
			
		}
		if (k) cout << endl;
	}
	
	return 0;
}

原文地址:https://www.cnblogs.com/mofushaohua/p/7789450.html