问题:
1.判断函数传参时忘记给arr2加[]
2.把if放在for之外,导致判断不出,程序报错
cpp
void reverse_right(char* right, char* left)
{
assert(left != NULL);
assert(right != NULL);
while (right > left)
{
char* temp = *right;
*right = *left;
*left = temp;
left++;
right--;
}
}
void turn_right(char* arr, int k)
{
assert(arr != NULL);
int len = strlen(arr);
assert(k >= 0);
//1
reverse_right(arr + len - 1, arr + len - k);
//2
reverse_right(arr + len - 1 - k, arr);
//3
reverse_right(arr + len - 1, arr);
}
int panduan_right(char arr1[], char arr2[])
{
int len = strlen(arr1);
int i = 0;
for ( i = 0; i < len; i++)
{
turn_right(arr1, 1);
if (strcmp(arr1, arr2) == 0)
{
return 1;
}
}
return 0;
}
int main()
{
char arr1[] = "cdeab";
char arr2[] = "abcde";
int ret = panduan_right(arr1, arr2);
if (ret == 1)
{
printf("y\n");
}
else
{
printf("n\n");
}
return 0;
}