문제

I am having difficulty in printing the longest common substring in a suffix tree.I can easily calculate the length of the longest common substring but having problems in actually finding the substring.Below is the code for Longest Common Substring in C++.Can anyone please help me out?

도움이 되었습니까?

해결책

Add variable:

int start = -1;

Replace:

ans=max(ans,l);

with:

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

The longest substrings starts at b[start], so to print the longest substring in the end:

printf("%.*s", ans, b + start);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top