Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int period(char str[]){
- int length = sizeof(str) / sizeof(char);
- int i,j,k,l;
- int period = length;
- // iterating each char in main string, except first char
- for (i=1; i<length/2; i++){
- if(str[i] == str[0]){
- int lengthDifference = i-1;
- bool check = false;
- if (lengthDifference+i <= length-1){
- check = true;
- }
- if (check){
- int tempPeriod = j+1;
- if (length%tempPeriod == 0){
- int reps = length / tempPeriod;
- bool checkReps = true;
- for (k=1; k< reps-1; k++){
- if (checkReps){
- for (l=0; l<tempPeriod; l++){
- if (str[l] != str[reps*tempPeriod + l]){
- checkReps = false;
- break;
- }
- }
- }
- }
- if (checkReps){
- period = tempPeriod;
- break;
- }
- }
- }
- }
- }
- return period;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement