问:判断数组是否是另一个数组的逆转数组
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include<string.h> #include<assert.h> void Mylift(char* left, char* right) { assert(left != NULL); assert(right != NULL); char rmp = 0; while (left < right) { rmp = *left; *left = *right; *right = rmp; right--; left++; } } void Ayue(char* arr, int k) { assert(arr); int sz = strlen(arr); assert(k < sz); Mylift(arr, arr + k - 1);//逆序左边 Mylift(arr + k, arr + sz - 1);//逆序右边 Mylift(arr, arr + sz - 1);//逆序整体 } int is_Ayue(char* s1, char* s2) { int len = strlen(s1); int i = 0; for (i = 0; i < len; i++) { Ayue(s1, 1);//每次逆转一个,因为这里的s1是变化的 int ret = strcmp(s1, s2); if (ret == 0) return 1; } return 0; } int main() { char arr1[] = "abcdef"; char arr2[] = "cdefab"; int t = is_Ayue(arr1, arr2); if (t == 1) printf("Yes\n"); else printf("No\n"); return 0; }
标签:arr,right,int,代码,练习,35,char,s1,left From: https://www.cnblogs.com/ayue6/p/17785133.html