FOJ1011 Power String

#include <stdio.h> #include <string.h> void GetNext(char strings[],int next[]);//KMP算法的获得next算法 char strings[1000001]; int next[1000001]; int main() { int len; int k,m; /*freopen("e://12.txt","r",stdin);*/ while (gets(strings)) { if (strings[0] == '.') { break; } else { len = strlen(strings); GetNext(strings,next); k = len-next[len]; m = len%k; if (m == 0) { m = len/k; } printf("%d/n",m); } } return 0; } void GetNext(char strings[],int next[]) { int i=0,j= -1; next[0] = -1; while (strings[i]!='/0') { if (j == -1||strings[i] == strings[j]) { i++; j++; next[i] = j; } else j = next[j]; } }

你可能感兴趣的:(算法,String,include)