如何在后缀树中打印字符串

How to print the string in a suffix tree

本文关键字:打印 字符串 后缀      更新时间:2023-10-16

我在打印后缀树中最长的公共子字符串时遇到困难。我可以很容易地计算出最长的公共子串的长度,但在实际找到子串时遇到了问题。下面是c++中最长公共子串的代码。有人能帮帮我吗?

添加变量:

int start = -1;

替换:

ans=max(ans,l);

:

if (l > ans) {
  ans = l;
  start = i;
}

最长的子字符串从b[start]开始,所以要打印末尾最长的子字符串:

printf("%.*s", ans, b + start);