周期串
Time Limit:1000MS Memory Limit:65536K
Total Submit:119 Accepted:38
Description
如果一个字符串可以由某个长度为k的字符串重复多次得到,我们说该串以k为同期。例如,abcabcabcabc以3为周期(注意,它也以6和12为周期)。
Input
连续输入一个长度不超过80的字符串。
Output
输出它的最小周期并换行。
Sample Input
HoHoHo
HelloHello
Sample Output
2
5
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1079 {
class Program {
static void Main(string[] args) {
string s;
while ((s = Console.ReadLine()) != null) {
int t = 0;
bool falg = true;
for (int i = 1; i <= s.Length; i++) {
if (s.Length % i == 0 && falg) {
string sb = s.Substring(0, i);
int j = 0;
for (j = i; j < s.Length; j += i) {
string temp = s.Substring(j, i);
if (temp != sb) {
break;
}
}
if (j == s.Length) { t = i; falg = false; break; }
}
}
Console.WriteLine(t);
}
}
}
}