I found this implementation on a website for printing the longest common subsequence. But it gives wrong answers for some reason even though the code seems right to me.
Here is the code:
lines 30-33 shouldn't even compile. This looks like a program written in c and then 'ported' to c++, poorly. There are much better functions in c++ that could have been used for this.
int m;
int n;
char X[m], Y[n];
std::cin >> m >> n;
The array size should be known at compile time
There are some compiler extension that may allow you to do that, but it is not standard
You need to remember that the code executes sequentially from top to bottom. So at line 32 the values of `m' and `n' are uninitialized (they contain garbage). Then it's very likely that you are accessing them out of bounds.
As an aside, I eventually gave up on my idea because, while LCS works flawlessly as a diff algorithm, its O(n*m) time is prohibitively expensive if you want to compare lists of millions of elements.