Files
python/RuMenJingDian/UVa/UVa455.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

31 lines
733 B
C++

#include <bits/stdc++.h>
using namespace std;
//周期串,使用环形串法求解
int main(void) {
int N;
char str[100];
cin >> N;
while (N--) {
cin >> str;
int len = strlen(str);
int t = 1;
while (true) {
int c = 0;
for (int i = 0; i < len; ++i) {
if (str[i] == str[(i + t) % len]) //看一看转几个字符能够恢复原位,这个余数用的好!
++c;
}
//每一个都对的上,才停止
if (c == len)
break;
++t;
}
cout << t << endl;
if (N != 0)
cout << endl;
}
return 0;
}