学习笔记之TAOCP--字符串查找(学习“结构之法”博客)

此问题为:

    问str1是否有str2

#include <iostream>
#include <string>
using namespace std;

bool match(string strLong,string strShort)
{
   size_t sS = strShort.length();
   size_t lS = strLong.length();
   int j;
   bool isMactch = true;
   for(int i = 0; i <= lS-sS; i++)
   {
   	 for(j = 0; j < sS; j++)
   	 {
   	 	if (strLong[i+j] != strShort[j])
			{
		       break;
			}
   	 }
   	 if(j==sS)
   	 return true;
   	
   }
   return false;
}


int main()
{  
  if(match("abc","abd")) 
   cout<<"Yes"<<endl;
   else{
   	cout<<"No"<<endl;
   }
}


你可能感兴趣的:(学习笔记之TAOCP--字符串查找(学习“结构之法”博客))