如何用C来寻找最长公共子串++如何用、最长

2023-09-11 02:07:19 作者:苍老的岁月为谁而等待

我在网上搜索了C ++的最长公共子串的实现,但未能找到一个体面的。我需要一个LCS算法返回字符串本身,所以它不只是LCS。

I searched online for a C++ Longest Common Substring implementation but failed to find a decent one. I need a LCS algorithm that returns the substring itself, so it's not just LCS.

我不知道,不过,我是多么的可以在多个字符串之间做到这一点。

I was wondering, though, about how I can do this between multiple strings.

我的想法是,检查最长的2串,然后去检查所有的人,但是这是一个非常缓慢的过程,需要管理很多长串的记忆,让我的程序很慢。

My idea was to check the longest one between 2 strings, and then go check all the others, but this is a very slow process which requires managing many long strings on the memory, making my program quite slow.

这是如何任何想法可以加快多个字符串?谢谢你。

Any idea of how this can be speeded up for multiple strings? Thank you.

重要修改 一,我给出的变量决定字符串的最长公共子需要在数量,这样我可以给10串,并找到所有的LCS(K = 10),或其中4 LCS,但我没有告诉其中4个,我一定要找到最好的4。

Important Edit One of the variables I'm given determines the number of strings the longest common substring needs to be in, so I can be given 10 strings, and find the LCS of them all (K=10), or LCS of 4 of them, but I'm not told which 4, I have to find the best 4.

推荐答案

下面是的优秀文章找到所有常见子的高效,具有在C的例子,这可能是矫枉过正如果需要只是最长,但它可能是更容易理解高于约后缀树的一般物品

Here is an excellent article on finding all common substrings efficiently, with examples in C. This may be overkill if you need just the longest, but it may be easier to understand than the general articles about suffix trees.