Cycle string of WLS |
Difficulty level: A; run time limit: 1000ms; operating space limit: 51200KB; code length limit: 2000000B |
Question Description |
If a string can be repeated multiple times by a string of length k, we say the string is a period of K. For example, ABCABCABCABC has a period of 3 (note that it also has periods of 6 and 12). Enter a string with a length of not more than 1000 to output its minimum period. |
Input |
A string consisting of a characters commonly used character |
Output |
Minimum period of input string |
Input example |
Abcabcabcabc |
Output example |
3 |
#include <cstdio>
#include <string>
#include <cstring>
using namespace Std;
int main ()
{
Char word[100];
scanf ("%s", word);
int len = strlen (word);
for (int i = 1; I <= len; ++i) {
If (len% i = = 0) {
int OK = 1;
for (int j = i; j < Len; ++j) {
if (word[j]! = word[j% i]) {
OK = 0;
Break
}
}
if (OK) {
printf ("%d\n", I);
Break
}
}
}
System ("PAUSE");
return 0;
}
WLS Cycle String (c + +)