1. 程式人生 > >poj 2406 Power Strings求子串在主串中最多疊加次數

poj 2406 Power Strings求子串在主串中最多疊加次數

scan processor ces include span for stdio.h std repr

  1. #include<stdio.h>
  2. #define M 1000010
  3. int n,next[M];
  4. char s[M];
  5. void getNext()
  6. {
  7. int i=1,j=-1;
  8. next[0]=-1;
  9. for(;s[i];i++){
  10. while(j!=-1&&s[j+1]!=s[i])j=next[j];
  11. if(s[j+1]==s[i])j++;
  12. next[i]=j;
  13. }
  14. n=i;
  15. }
  16. int main()
  17. {
  18. while(scanf("%s",s),s[0]!=‘.‘){
  19. getNext();
  20. if(n%(n-next[n-1]-1))puts("1");
  21. else printf("%d\n",n/(n-next[n-1]-1));
  22. }
  23. return 0;
  24. }

poj 2406 Power Strings求子串在主串中最多疊加次數