当前位置:网站首页>KMP! You deserve it!!! Run directly!
KMP! You deserve it!!! Run directly!
2022-06-11 18:41:00 【Little doctor·】
Written this time kmp The algorithm is based on next Array to move and compare pattern strings , according to nextval The comparative movement of is still under consideration , In fact, it is (wo) One (bi) sentence (jiao) generation (cai) Code thing .
Because of the time, I won't hang it out , I'll send it after I've changed it !
#include <iostream>
#include <cstdlib>
#include <vector>
#define maxsize 100
using namespace std;
typedef struct String{
string string;
int length;
}String;
int *get_next(String S,int *next)
{
int i=0;
int j=-1;
next[0]=-1;
while(i<=S.length)
{
if(j==-1||S.string[i]==S.string[j])
{
++i;
++j;
next[i]=j;
}
else
j=next[j];
}
return next;
}
int KMP(String Str,String S,int *next,int *nextval)
{
int i=0;
int j=0;
while(i<Str.length&&j<S.length)
{
if(j==-1||Str.string[i]==S.string[j])
{
i++;
j++;
}
else
{
j=next[j];
}
}
if(j==S.length)
return i-S.length;
else
return -1;
}
int main()
{
struct String Str;// Main string
struct String S; // Pattern string
Str.string="aabghjvacabaababaabo";
Str.length=20;
S.string="abaab";
S.length=5;
//int *next=(int *)malloc(S.length*sizeof(int));
int *next=new int[5];
next=get_next(S,next);
cout<<"next--main"<<endl;
for(int i=0;i<S.length;i++)
{
cout<<next[i]<<" ";
}
cout<<endl;
cout<<"KMP"<<endl;
for(int i=0;i<S.length;i++)
{
cout<<next[i]<<" ";
}
cout<<endl;
int temp=KMP(Str,S,next,nextval);
if(temp==-1)
cout<<" Matching failure "<<endl;
else
cout<<" The match is successful "<<endl<<" Matching position :"<<temp<<endl;
return 0;
}
Buried pit !!!!
It took a whole week to write an algorithm for baked bun slices , What a disgrace , I am ashamed of my award !!
The algorithm is really hand-made without writing ! But I really don't have time !! Is dubious !
This buried pit
1. Comparison of stack area and heap area
2. About the innocent recycling of array memory !!!( In fact, the essence is the first
A problem )
3. I would like to inform you , Be sure to read clearly when you write kmp in next The beginning of the array
The subscript is 0 still 1. It's important !!!
4. There seems to be nothing left !
Good night, ! I wish you nb!
边栏推荐
- Swagger2简单使用
- [c language] output the students within the specified score range with the structure
- labelme进行图片数据标注
- 牛客刷题——part7
- MATLAB 保存imshow绘制图片到指定文件夹中的两种方法
- 基于TI AM5728 + Artix-7 FPGA开发板(DSP+ARM) 5G通信测试手册
- Mysql深入完全学习---阶段1---学习总述
- Prevent enemy tanks from overlapping
- Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics
- 开发中必备的文件的上传与下载
猜你喜欢

Dynamic explosion effect
![[c language] output the students within the specified score range with the structure](/img/40/cbd7fe5aafbaeb6237e6d257455e5e.png)
[c language] output the students within the specified score range with the structure

* Jetpack 笔记 使用DataBinding

为何TI的GPMC并口,更常被用于连接FPGA、ADC?我给出3个理由
制造出静态坦克
2022成年礼,致每一位高考学子

Swagger2简单使用
Mysql从0到1的完全深入学习--阶段二---基础篇
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics

金融银行_催收系统简介
随机推荐
添加自己喜欢的背景音乐
信号的处理与捕捉
[c language] limit the number of searches and output the maximum value found in the number of internal searches
平衡搜索二叉树——AVL树
Combination sum of 39 questions
2022成年礼,致每一位高考学子
Async leads to unexpected function results and changes the intention of the original code; await is only valid in async functions and the top level bodies of modules
Ubuntu installs PSQL and runs related commands
非递归实现二叉树的前、中、后序遍历
Surveillance des fonctions de perte avec visdom
开发中必备的文件的上传与下载
Signal processing and capture
Specific methods for JS to realize full screen display
力扣刷题——根据二叉树创建字符串
Deploy a go MSSQL API endpoint on SAP kyma
基于TI AM5728 + Artix-7 FPGA开发板(DSP+ARM) 5G通信测试手册
力扣32题最长有效括号
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics
Prevent enemy tanks from overlapping
Function development of user information management