Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. int period(char str[]){
  2.     int length = sizeof(str) / sizeof(char);
  3.     int i,j,k,l;
  4.     int period = length;
  5.     // iterating each char in main string, except first char
  6.     for (i=1; i<length/2; i++){
  7.         if(str[i] == str[0]){
  8.             int lengthDifference = i-1;
  9.             bool check = false;
  10.             if (lengthDifference+i <= length-1){
  11.                 check = true;
  12.             }
  13.             if (check){
  14.                 int tempPeriod = j+1;
  15.                 if (length%tempPeriod == 0){
  16.                     int reps = length / tempPeriod;
  17.                     bool checkReps = true;
  18.                     for (k=1; k< reps-1; k++){
  19.                         if (checkReps){
  20.                             for (l=0; l<tempPeriod; l++){
  21.                                 if (str[l] != str[reps*tempPeriod + l]){
  22.                                     checkReps = false;
  23.                                     break;
  24.                                 }
  25.                             }
  26.                         }      
  27.                     }
  28.                     if (checkReps){
  29.                         period = tempPeriod;
  30.                         break;
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.     }
  36.     return period;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement