Logic - Given 2 strings, how to know how many moves I make when I transform the first string in the second

1

Hello, how are you? I have 2 strings, and I need to calculate the total number of moves to become the first string in the second string.

string palavra1 = "gato"
string palavra2 = "pato"

replacing the "G" of the cat "P", I transform "cat" into "duck."

but could also be the strings

string palavra1 = "cavalo";
string palavra2 = "pato";

In this case the total number of moves would be 4. because it would remove C (1) and A (2) and trade V for P (3) and L for T (4)

Can anyone help me? Abs,

    
asked by anonymous 09.12.2018 / 04:12

1 answer

-1

An algorithm that does this is Greater Common Subsequence or in English Longest Common Subsequence .

The first link, I had to point to a Google search, because I did not find a more immutable reference. In the second, go to the Wikipedia page in English ... but have some implementation examples there.

This algorithm can be made to compare any type of sequence, it can be two strings, two lists of strings representing the lines of two texts, etc.

    
09.12.2018 / 05:39