字符串匹配算法 [英] String matching algorithm
问题描述
说我有3串。然后1多个字符串。
是否有一个算法,可以让我找到其中前3个字符串之一的第四根弦最匹配?
没有琴弦的将是精确匹配,我只是试图找到最接近的匹配。
如果该算法已经存在于STL,这将是很好的。
Say I have 3 strings. And then 1 more string.
Is there an algorithm that would allow me to find which one of the first 3 strings matches the 4th string the most?
None of the strings are going to be exact matches, I'm just trying to find the closest match.
And if the algorithm already exists in STL, that would be nice.
在此先感谢。
推荐答案
您没有指定究竟你的意思是匹配最,所以我假设你没有precise要求。在这种情况下,在一个合理的度量 Levenshtein距离的。简单地计算每个三串和第四之间的Levenshtein距离,并选择那个给出最低距离
You don't specify what exactly you mean by "matches the most", so I assume you don't have precise requirements. In that case, Levenshtein distance in a reasonable metric. Simply compute the Levenshtein distance between each of the three strings and the fourth, and pick the one that gives the lowest distance.
这篇关于字符串匹配算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!