Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.2 字符串包含 新方法 #455

Open
pjbruce opened this issue Nov 28, 2017 · 0 comments
Open

1.2 字符串包含 新方法 #455

pjbruce opened this issue Nov 28, 2017 · 0 comments

Comments

@pjbruce
Copy link

pjbruce commented Nov 28, 2017

#define NO_OF_CHARS 256

char b[] = "ABGAA67";
char a[] = "AG7";


int aASCII[NO_OF_CHARS];
int bASCII[NO_OF_CHARS];
for (int i = 0; i < NO_OF_CHARS; i++) 
{
	aASCII[i] = -1;
	bASCII[i] = -1;
}

for (int i = 0; i < strlen(a); i++)
{
     aASCII[(int) a[i]] = i;
}

for (int i = 0; i < strlen(b); i++)
{
	bASCII[(int) b[i]] = i;
}

int findCount = 0;

for (int i = 0; i < NO_OF_CHARS; i++)
{
	if (aASCII[i] != -1 && bASCII[i]!=-1)
	{
		findCount++;
	}

}

if (findCount == strlen(a))
{
	printf("find");
}

Reference:https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
http://www.geeksforgeeks.org/pattern-searching-set-7-boyer-moore-algorithm-bad-character-heuristic/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant