• 编程之类 字符串包括问题


    /* 
       字符串 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;
    }

  • 相关阅读:
    网页如何展示PPT文档
    关于DLL中Resources文件修改
    解決 IE10 浏览器无法使用 ASP.NET From 验证登录的问题
    Ubuntu 13.10 下安装 eclipse
    Ubuntu 13.10 下安装node
    关于AutoCAD.NET的辅助方法
    Linux下安装oracle11g
    Linux下配置VNC
    Linux下安装McAfee防病毒软件(企业版本)
    .net 下word 中的图片与文字分离
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7371944.html
Copyright © 2020-2023  润新知