// .判断一个字符串是否为另外一个字符串旋转之后的字符串。
// 例如:给定s1 = AABCD和s2 = BCDAA,返回1,给定s1=abcd和s2=ACBD,返回0
#include <stdio.h>
#include <string.h>
#include <assert.h>
int rotate(char *p, char *q)
{
assert(p != NULL && q != NULL);
strncat(p,p,strlen(p));
if (strstr(p, q) == NULL)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
char p[20] = "AABCD";
char *q = "BCDAA";
char r[20] = "abcd";
char *s = "ACBD";
printf("%d\n", rotate(p, q));
printf("%d\n", rotate(r, s));
return 0;
}
<img src="https://img-blog.csdn.net/20150704100324871?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />