Ladies_Man

Periodical Prefixes (Пер.префиксы)

Dec 17th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     int pi[40] = {0}, i, t = 0;
  8.     char *str = argv[1];
  9.     for (i = 1; i <= strlen(str); i++) {
  10.         while ((t != 0) && (str[t] != str[i])) t = pi[t - 1];
  11.         if (str[t] == str[i]) t++;
  12.         pi[i] = t;
  13.         if (i > 1 && (i % (i - pi[i - 1]) == 0) && (i != (i - pi[i - 1])))
  14.             printf("%d %d\n", i, i/(i - pi[i - 1]));
  15.         }
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment