BP算法

时光总嘲笑我的痴心妄想 提交于 2020-02-28 17:40:56
#define _CRT_SECURE_NO_WARNINGS
#include "string.h"
#include "stdio.h"
/*BP算法的实现
*@auther:ck
*/
/*函数声明*/
int Index(char *Buffer, char *buffer, int pos,int Count);
int Strlen(char *Buffer);
/*main*/
void  main(void) {
	int index;
	int count;
	char Buffer[20] ="acfgyhgtuoitmn";
	char buffer[6] ="tuoit";
	count = Strlen(buffer);
	index=Index(Buffer, buffer,2, count);
	for (int i=0; i <count;i++ ) {
		printf("%c",Buffer[index++]);
	}
	printf("\n");
	system("pause");
}
/*
*@param:pos:need found position
*@return:if found return position number ,nor return 0
*/
int Index(char *Buffer, char *buffer, int pos,int Count) {
	int B, b=0;
	if (pos > Strlen(Buffer))return 0;
	B = pos - 1;
	while (Buffer[B] !='\0'){
		if (Buffer[B] == buffer[b]) {
				B++; b++;
		}
		else
		{
		if (b== Count){
				return B-b;/*return pos*/
		}
				B = B - b + 1;
				b = 0;
		}
	}
	return 0;
}
/*Number of statistical character */
unsigned int Strlen(char *Buffer) {
	unsigned int count=0;
	for (int i = 0;Buffer[i] != '\0'; i++) {
		count++;
	}
	return count;
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!