'commit'
This commit is contained in:
30
RuMenJingDian/UVa/UVa455.cpp
Normal file
30
RuMenJingDian/UVa/UVa455.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user