Charlie has a magic mirror. The mirror shows right rotated versions of a given word
To generate different right-rotations of a word, write the word in a circle in clockwise order, then start
reading from any given character in clockwise order till you have covered all the characters
For example, in the word "sample'if we start with 'p. we get the right rotated word as plesary. There
are six such right rotations of "sample including itself
The inputs to the function is SameReflection consists of two strings, wordland word?
The function returns 1 if wordland word are right rotations of the same word and -1 if they are not
Both wordland word2 will strictly contain characters between a'-Z (lower case letters
Answers
In the word "sample'if we start with 'p. we get the right rotated word as plesary.
There are six such right rotations of "sample including itself
The inputs to the function is SameReflection consists of two strings
The function returns 1 if wordland word are right rotations of the same word and -1 if they are not
Both wordland word2 will strictly contain characters between a'-Z (lower case letters
Explanation:
#include<stdio.h> #include<string.h>
// Print all the rotated string.
void printRotatedString(char str[]) { int len = strlen(str); // Generate all rotations one by one and
print char temp[len];
for (int i = 0; i < len; i++)
{ int j = i; // Current index in str
int k = 0; // Current index in temp // Copying the second part from the point // of rotation.
while (str[j] != '\0')
{ temp[k] = str[j]; k++; j++;
} // Copying the first part from the point // of rotation.
j = 0; while (j < i)
{
temp[k] = str[j]; j++; k++;
}
if(temp[0]=='p')
{
printf("%s",temp); break;
}
}
} // Driven Program
int main()
{
char str[] = "sample";
printRotatedString(str);
return 0;
}