Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. A string S = S[0]S[1] . . .S[N-1] consisting of N characters is given. The K-th cyclic
  2. shift of this string, where 0 <= K < N, is a string T defined as follows:
  3.  
  4. T = S[K]S[K+1]...S[N-1]S[O]S[1]...S[K-1], for 0 < K < N,
  5. T = S, for K=0.
  6. For example, these are all cyclic shifts of the string S = "abcdefgh":
  7.  
  8. - "abcdefgh" is 0th cyclic shift of "abcdefgh"
  9. - "bcdefgha" is 1st cyclic shift of "abcdefgh"
  10. - "cdefghab" is 2nd cyclic shift of "abcdefgh"
  11. - "defghabc" is 3rd cyclic shift of "abcdefgh"
  12. - "efghabcd" is 4th cyclic shift of "abcdefgh"
  13. - "fghabcde" is Sth cyclic shift of "abcdefgh"
  14. - "ghabcdef" is 6th cyclic shift of "abcdefgh"
  15. - "habcdefg" is 7th cyclic shift of "abcdefgh"
  16. If a cyclic shift of a given sting S is equal to S, then it is called a cyclic
  17. automorphism of S. Each string has at least one cyclic automorphism, namely
  18. the 0th cyclic shift. For example, the 0th and 3rd cyclic shifts of the
  19. string "byebye" constitute all of its cyclic automorphisms.
  20. Write a function:
  21.  
  22. int solution(String s);
  23. that, given a string S of length N, returns the number of cyclic automorphisms
  24. of S. For example, given S = "byebye", the function should return 2, as
  25. explained in the example above. Assume that:
  26.  
  27. - N is an integer within the range [1..1,000.000];
  28. - string S consists only of lower-case letters (a-z).
  29. Complexity:
  30.  
  31. - expected worst-case time complexity is O(N);
  32. - expected worst-case space complexity is O(N) (not counting the storage required for input arguments).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement