《编程之美3.1:字符串移位包含问题》
2010-08-13 15:00
381 查看
给定两个字符串s1和s2,要求判定s2是否能够通过s1循环移位得到的字符串包含。例如,给定s1=AABCD和s2=CDAA,返回true;给定s1=ABCD和s2=ACBD,返回false。
/* ============================================================================ Name : Strstr.c Author : QiBaoyuan Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { char src[] = "AABBCD";//sizeof(src)=7,strlen(src)=6 char des[] = "CDAA"; int len = strlen(src); char *con = (char*) malloc(len * 2 + 1); strcpy(con, src); strcat(con, src); if (strstr(con, des) != NULL) printf("ok"); else printf("not exists"); return EXIT_SUCCESS; }
相关文章推荐
- 编程之美3.1—字符串移位包含问题
- 《编程之美》- 3.1 - 字符串移位包含的问题
- 编程之美3.1 字符串移位包含问题
- 编程之美3.1 字符串移位包含的问题
- [编程之美3.1]字符串移位包含的问题
- 3.1 字符串移位包含的问题——编程之美
- 编程之美3.1 字符串移位包含问题
- 编程之美:3.1 字符串移位包含的问题
- 编程之美3.1——字符串移位包含的问题(KMP算法)
- 编程之美——3.1 字符串移位包含的问题
- 《编程之美》 - 3.1 字符串移位包含的问题( 不用strstr()的解法 )
- 《编程之美》3.1 字符串移位包含的问题
- 编程之美-3.1字符串移位包含问题
- 字符串移位包含问题(编程之美3.1)
- 编程之美3.1 字符串移位包含问题
- 编程之美:第三章 结构之法 3.1字符串移位包含的问题
- 编程之美——3.1字符串移位包含问题
- 编程之美——3.1字符串移位包含问题
- 编程之美3.1字符串移位包含问题
- 《编程之美》——3.1字符串移位包含的问题