Description
Implement the LCS algorithm introduced in the class. You are required to output all possible LCS. The output set of LCS should in lexicographical order. Same LCS only need to output once.
Examples
Input:
springtime
printing
Output:
printi
Input:
basketball
krzyzewski
Output:
ke
sk
Note
-
To make life easier, the input sequences only contain
lower case letters
. -
You can use containers and common libraries to simplify coding.
Reference Code
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
set<string> LCS(string X, string Y)
{
}
int main()
{
string X, Y;
cin >> X;
cin >> Y;
set<string> lcs = LCS(X, Y);
// print set elements
for (string str : lcs)
{
cout << str << endl;
}
return 0;
}
tip: