Untitled
unknown
c_cpp
4 years ago
678 B
10
Indexable
#include <iostream>
int solve2(std::string x, std::string y)
{
int lengthX=x.lenth();
int lengthY=y.length();
int** L = new int*[lengthX+1];
for (int i = 0; i < lengthX + 1; i++)
L[i] = new int[lengthY + 1];
for (int i = 0; i <= lengthX; i++)
{
for (int j = 0; j <= lengthY; j++)
{
if (i == 0 || j == 0)
L[i][j] = 0;
else if (x[i - 1] == y[j - 1])
{
L[i][j] == L[i - 1][j - 1] + 1;
}
else
L[i][j] = std::max(L[i - 1][j], L[i][j - 1]);
}
}
return L[lengthX][lengthY];
}
int main()
{
std::string A = "ABCBDAB";
std::string B = "BDCABA";
std::cout<<"Lungimea este: "<<solve2(A,B);
}Editor is loading...