标签:c语言 判断一个字符串是否为另外一个字符串旋转之后的字符串
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include <string.h> void reserve(char *left, char*right) { while (left < right) { char tmp = *left; *left = *right; *right = tmp; left++; right--; } } void left_reserve(char arr[], int k) { int len = strlen(arr) - 1; char *pstart = &arr[0]; char *pend = arr + len; reserve(pstart, pstart + k - 1); reserve(pstart + k, pend); reserve(pstart, pend); } void right_reserve(char arr[], int k) { int len = strlen(arr) - 1; char *pstart = &arr[0]; char *pend = arr + len; reserve(pstart, pstart + len - k); reserve(pend - k+1, pend); reserve(pstart, pend); } int main() { char arr[10] = "AABCD"; char arr2[10] = "ABCDA"; char *p = arr; int k = 5; while (k) { left_reserve(arr, k); if (strcmp(arr, arr2) == 0) { printf("1\n"); break; } right_reserve(p, k); if (strcmp(p, arr2) == 0) { printf("1\n"); break; } k--; } if (0 == k) { printf("0\n"); } system("pause"); }
【C语言】【笔试题】【面试题】判断一个字符串是否为另外一个字符串旋转之后的字符串
标签:c语言 判断一个字符串是否为另外一个字符串旋转之后的字符串
原文地址:http://10740329.blog.51cto.com/10730329/1709401