编程之类 字符串包含问题
来源:互联网 发布:网络手机卡资费对比 编辑:程序博客网 时间:2024/06/06 11:46
/*
字符串 s1 能否 通过 循环移位得到 字符串 s2
</pre><pre name="code" class="cpp"> 如 s1="AC" s2="CACA"==>is true
s1="ABCDEFR" s2="RA"==>is true;
s1="ABCDEFR" s2="DFA" ==>is false;
*/
#include<iostream>using namespace std;bool IsContainer( char*str1, char*str2,int& startIndex){int len1=strlen(str1);int len2=strlen(str2);char* temp1=str1;char* temp2=str2;int i=0,j=0;bool flag=false;while(true){while(i<len1){if(temp1[i]==temp2[0]){int i_2=i;if(i_2==len1-1)i_2=0;else i_2++;j=1;bool exit=false;while(j<len2){if(i_2<len1 && temp1[i_2]!=temp2[j]){exit=true;break;}if(i_2==len1-1 && temp1[i_2]==temp2[j]){i_2=0;j++;continue;}i_2++;j++;}if(!exit){flag=true;startIndex=i+1;break;}}i=i+1;}if(flag){break;}if(i==len1)break;}return flag;}int main(){char*str1="AC";char*str2="CACA";int startIndex=0;if(IsContainer(str1,str2,startIndex)){cout<<"is true"<<" startIndex= "<<startIndex<<endl;}else cout<<"is false"<<endl;char*str3="ABCDEFR";char*str4="RA";if(IsContainer(str3,str4,startIndex)){cout<<"is true"<<" startIndex= "<<startIndex<<endl;}else cout<<"is false"<<endl;char*str5="ABCDEFR";char*str6="DFA";if(IsContainer(str5,str6,startIndex)){cout<<"is true"<<" startIndex= "<<startIndex<<endl;}else cout<<"is false"<<endl;return 0;}
0 0
- 编程之类 字符串包含问题
- 编程之美---->字符串移位包含问题
- 程序员编程艺术--2、字符串包含问题
- 19:字符串移位包含问题(1.7编程基础之字符串)
- 《编程之美3.1:字符串移位包含问题》
- 程序员编程艺术:第二章、字符串是否包含问题
- 《编程之美》3.1 字符串移位包含的问题
- 编程之美-3.1字符串移位包含问题
- 编程之美3.1 字符串移位包含问题
- 字符串移位包含问题(编程之美3.1)
- 编程之美--字符串循环移位包含问题
- 编程之美——字符串移位包含问题
- [编程之美3.1]字符串移位包含的问题
- 字符串移位包含的问题(编程之美)
- 【编程之美】字符串移位包含的问题
- 编程之美3.1 字符串移位包含问题
- 编程之美3.1 字符串移位包含问题
- 编程之美3.1字符串移位包含问题
- ListView(2)——自定义Adapter
- HDU 2203(KMP) 亲和串
- 墨綠的黃昏
- [python] 爬取网站所有的URL
- 进程间通信----Messenger
- 编程之类 字符串包含问题
- 转载设计模式介绍
- Windows Server 2003单网卡搭建VPN
- 将表中子字段的值按主字段分组后以空格连接作为一个字段
- 个人整理的一些java开发基础
- 设计模式详解之桥接模式
- B树的定义、插入和删除
- HDU5344 MZL's xor
- 关于mini2440启动代码中中断的产生原理分析