You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
703 B
31 lines
703 B
#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;
|
|
}
|