字符串查找子串,主串A="ababcabcacbab",要求在A中查找B="abcac"

#include
#include
#include
using namespace  std;
class Solution
{
public:
	char  *strFind(char * string, char *substring)
	{
		if (string == NULL &&substring == NULL)
			return NULL;
		int m = strlen(string);
		int n = strlen(substring);
		int j;
		if (m < n)
			return NULL;
		for (int i = 0; i <= m - n; i++)
		{
			for (j = 0; j <= m - n; j++)
			{
				if (string[i + j] != substring[j])
					break;
			}
			if (j == n)
				return string + i;

		}
	}
};

int main()
{
	char *string = "ababcabcacbab";
	char *substring = "abcac";
	Solution S1;
	cout<

 

你可能感兴趣的:(字符串查找子串,主串A="ababcabcacbab",要求在A中查找B="abcac")