Professional Documents
Culture Documents
Experiment 4: Aim-To Implement Longest Common Subsequence Problem
Experiment 4: Aim-To Implement Longest Common Subsequence Problem
Code-
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
inti = m, j = n;
while (i> 0 && j > 0)
{
if (X[i-1] == Y[j-1])
{
lcs[index-1] = X[i-1];
i--; j--; index--;
}
cout<< "LCS of " << X << " and " << Y << " is " <<lcs;
cout<<" of length:"<<strlen(lcs);
}
int main()
{
cout<<"Rishabh Raj"<<endl;
cout<<"45514803117"<<endl;
char X[20];
char Y[20];
cout<<"Enter string 1:";
cin>>X;
cout<<"Enter string 2:";
cin>>Y;
int m = strlen(X);
int n = strlen(Y);
lcs(X, Y, m, n);
}