标签:des blog io ar sp for on div log
Description
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
#include<cstdio> #include<cstring> #define LL long long inline void write(LL a) { if (a<0){printf("-");a=-a;} if (a>=10)write(a/10); putchar(a%10+‘0‘); } inline void writeln(LL a){write(a);printf("\n");} int next[1000010]; char s[1000010]; int l,j,k; inline void pre() { memset(next,0,sizeof(next)); j=0; for (int i=2;i<=l;i++) { while (j>0&&s[j+1]!=s[i])j=next[j]; if (s[j+1]==s[i])j++; next[i]=j; } } int main() { while (scanf("%s",s+1)&&s[1]!=‘.‘) { l=strlen(s+1); pre(); int len=l-next[l]; if (l%len)writeln(1); else writeln(l/len); } return 0; }
标签:des blog io ar sp for on div log
原文地址:http://www.cnblogs.com/zhber/p/4162960.html