字符串搜索中,BFS算法很巧妙,个人认为BFS算法效率是最高的. [StringSearch]就是根据BFS算法并优化. 使用方法: string s = "中国|国人|zg人|fuck|all|as|19|http://|ToolGood"; string test = "我是中国人"; StringSearch ss = new StringSearch(); ss.SetKeywords(s.Split('|')); var allss = ss.FindAl…
Aho和Corasick对KMP算法(Knuth–Morris–Pratt algorithm)进行了改进,Aho-Corasick算法(Aho-Corasick algorithm)利用构建树,总时间复杂度是O(n).原理图如下(摘自Aho-Corasick string matching in C#): Building of the keyword tree (figure 1 - after the first step, figure 2 - tree with the fail fu…
思路:宽度优先搜索(BFS算法) #include<iostream> #include<stdio.h> #include<cmath> #include<cstring> using namespace std; int a,b; struct node{ int num; int step; }; node que[10000];//默认初始化为0 int visit[10000];//默认初始化为0 int prime(int d){ if(d<…