标签:style blog http java color os io for
abcd aaaa ababab .
1 4 3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long 10 #define INF 0x3f3f3f 11 using namespace std; 12 const int maxn = 1000100; 13 char str[maxn]; 14 int fail[maxn]; 15 void getFail(int &len) { 16 int i,j; 17 len = strlen(str); 18 fail[0] = fail[1]; 19 for(i = 1; i < len; i++) { 20 j = fail[i]; 21 while(j && str[j] != str[i]) j = fail[j]; 22 fail[i+1] = str[j] == str[i] ? j+1:0; 23 } 24 } 25 int main() { 26 int len; 27 while(gets(str) && str[0] != ‘.‘) { 28 getFail(len); 29 if(len%(len-fail[len])) puts("1"); 30 else printf("%d\n",len/(len-fail[len])); 31 } 32 return 0; 33 }
xtu字符串 B. Power Strings,布布扣,bubuko.com
标签:style blog http java color os io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3868915.html