⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 实验中我们使用了四种方法进行串匹配
💻 CPP
字号:
#include"algo4.h"
void main()
{
	for(int i=0;i<13;i++)
	{
	int tmun,pmun,a,asize;
	char *test,*par;
	LONGLONG begin,end;
	LARGE_INTEGER time1;
	cout<<"输入文本串长度的2次方指数:";
	cin>>tmun;
	cout<<"输入模式串长度:";
	cin>>pmun;
	cout<<"输入字符集大小(1~26):";
	cin>>asize;
	tmun=(int)pow(2,tmun);
	test=(char*)malloc(sizeof(char)*tmun);
	par=(char*)malloc(sizeof(char)*pmun);
	//srand(time(NULL));
	for(int i=0;i<tmun;i++)
	{
		a=rand()%asize+97;
		test[i]=a;
	}
	for(i=0;i<pmun;i++)
	{
		a=rand()%asize+97;
		par[i]=a;
	}
//	cout<<test<<endl;
//  cout<<par<<endl;
	cout<<"Shift Or串匹配算法"<<endl;
	QueryPerformanceCounter(&time1);
    begin=time1.QuadPart;
	so(par,pmun,test,tmun,asize);
    QueryPerformanceCounter(&time1);
    end=time1.QuadPart;
	cout<<"the RUNNINGTIME of Shift Or"<<"  "<<(double)(end-begin)<<endl;
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
	cout<<"horspool串匹配算法"<<endl;
	QueryPerformanceCounter(&time1);
    begin=time1.QuadPart;
    horspool(par,pmun,test,tmun,asize);
	QueryPerformanceCounter(&time1);
    end=time1.QuadPart;
	cout<<"the RUNNINGTIME of horspool"<<"  "<<(double)(end-begin)<<endl;
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    cout<<"quick search串匹配算法"<<endl;
	QueryPerformanceCounter(&time1);
    begin=time1.QuadPart;
	QS(par,pmun,test,tmun,asize);
	QueryPerformanceCounter(&time1);
    end=time1.QuadPart;
	cout<<"the RUNNINGTIME of horspool"<<"  "<<(double)(end-begin)<<endl;
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
	cout<<"kmp串匹配算法"<<endl;
	QueryPerformanceCounter(&time1);
    begin=time1.QuadPart;
	kmp(test,par,tmun,pmun);
	QueryPerformanceCounter(&time1);
    end=time1.QuadPart;
	cout<<"the RUNNINGTIME of horspool"<<"  "<<(double)(end-begin)<<endl;
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
	getchar();
	system("cls");
	}


}

/*LARGE_INTEGER time1;
LONGLONG begin,end;
QueryPerformanceCounter(&time1);
begin=time1.QuadPart;
INSERT_SORT(integ1,n);
QueryPerformanceCounter(&time1);
end=time1.QuadPart;
cout<<"the RUNNINGTIME of INSERT_SORT"<<"  "<<(double)(end-begin)<<endl;*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -