Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. void zf(char* s, int* p, int len)
  5. {
  6.     for(int i = 0; i < len; i ++) p[i] = 0;
  7.     for(int i = 1; i < len; ++i)
  8.     {
  9.         int t = p[i - 1];
  10.         while(t > 0 && s[i] != s[t])
  11.             t = p[t - 1];
  12.         if(s[i] == s[t]) ++t;
  13.         p[i] = t;
  14.     }
  15. }
  16.  
  17. int main(int argv, char* argc[])
  18. {
  19.  
  20.     //freopen("input.txt", "r", stdin);
  21.     //printf("%s\n", argc[1]);
  22.     char* str = argc[1];
  23.     //scanf("%s", str);
  24.     int p[strlen(str)];
  25.     zf(str, p, strlen(str));
  26.     for(int i = 2; i <= strlen(str); i ++)
  27.     {
  28.         if(i % (i - p[i - 1]) == 0 && p[i - 1] != 0)
  29.         {
  30.             printf("%d %d\n", i, i / (i - p[i - 1]));
  31.         }
  32.     }
  33.     return 0;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement