标签:c/c++
#include<stdio.h> #include<string.h> #include<stdlib.h> void reveser_str(char* start,char*end)//字符串整体逆序 { while (start < end) { char tmp = *start; *start = *end; *end = tmp; start++; end--; } } int spin(char* s1, char* s2) { int len=strlen(s1); char*start = s1; //abcdeefeg\0 char*end = s1 + len - 1; //gefeedcba\0 egabcdeef efegabcde reveser_str(start,end); //efegabcde\0 char* eos = start; while (*eos != ‘\0‘) { if(*eos == *s2) { reveser_str(start, eos); reveser_str(eos+1, end); if (strcmp(s1, s2) == 0) { return 1; } else { reveser_str(start, eos); reveser_str(eos + 1, end); } } eos++; } return 0; } int main() { char s1[] = "abcdefef"; char s2[] = "cdefefab"; int ret=spin(s1, s2); if (ret == 1) { printf("yes"); } else { printf("no"); } system("pause"); return 0; }
标签:c/c++
原文地址:http://lingdandan.blog.51cto.com/10697032/1709650