//空间换时间 bool func(char * s1, char * s2) { assert(s1); assert(s2); char * temp = new char[strlen(s1)*2 + 1]; strcpy(temp,s1); strcat(temp,s1); if(strstr(temp, s2) != NULL) return true; else return false; delete[] temp; } //循环判断 bool func2(char * s1, char * s2) { assert(s1); assert(s2); size_t len = strlen(s1); for(int i=0;i<len;i++) { char temp = s1[0]; for(int j=0;j<len-1;j++) s1[j] = s1[j+1]; s1[len-1]=temp; if(strstr(s1,s2) != NULL) return true; } return false; } int _tmain(int argc, _TCHAR* argv[]) { char s1[] = "ABCD"; //不能用char * s1 = "ABCD",因为这样的话是申请一个常量字符串,不允许被修改 char s2[] = "BCDA"; if(func(s1,s2)) printf("true"); else printf("false"); if(func2(s1,s2)) printf("true"); else printf("false"); }