| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 34601 | Accepted: 14319 |
Description
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
Source
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char str[1000005];
int next[1000005];
int main() {
while(scanf("%s", str) && str[0] != '.') {
int i = 0, j = -1, len = strlen(str);
next[0] = -1;
while(i < len) {
if(j == -1 || str[i] == str[j]) next[++i] = ++j;
else j = next[j];
}
if(len % (len - next[len]) == 0) printf("%d\n", len / (len - next[len]));
else printf("1\n");
}
return 0;
}
POJ - 2406 - Power Strings (KMP)
原文地址:http://blog.csdn.net/u014355480/article/details/43899389