gpt4 book ai didi

c++ - 如何打印后缀树中的字符串

转载 作者:行者123 更新时间:2023-11-30 19:47:16 25 4
gpt4 key购买 nike

我在打印后缀树中的最长公共(public)子字符串时遇到困难。我可以轻松计算最长公共(public)子字符串的长度,但在实际查找子字符串时遇到问题。下面是 C++ 中最长公共(public)子字符串的代码。可以有人请帮帮我吗?

最佳答案

添加变量:

int start = -1;

替换:

ans=max(ans,l);

与:

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

最长的子串从b[start]开始,因此要在末尾打印最长的子串:

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

关于c++ - 如何打印后缀树中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22352337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com