例如:给定s1 =AABCD和s2 = BCDAA,返回1
给定s1=abcd和s2=ACBD,返回0.
AABCD左旋一个字符得到ABCDA
AABCD右旋一个字符得到DAABC
思路:把AABCD复制两遍,看结果是否在AABCDAABCD 中
(左旋和右旋的结果都在AABCDAABCD 中)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int find_round(char *str, char *find){
char tmp[256] = { 0 };
strcpy(tmp, str); //在 tmp 里面将 str 写了两遍
strcat(tmp, str);
return strstr(tmp, find) ? 1 : 0;
}
int main(){
printf("%d\n", find_round("ABCDE", "DEABC"));
system("pause");
return 0;
}