Title details:
Traditional edit distance there are three kinds of operation, namely the increase, delete, change, we have to discuss now edit distance allows only two operations, by adding one character at a time, delete one character at a time, we pray for the edit distance of two strings, or a string into a string of other minimum number of operations,
Input format:
Multiple sets of data, two lines of each set of data, each row of a string, each string length less than 1000, only capital English letters,
The output format:
Each group of data output a line contains an integer, said needs at least the number of operation,
Answer:
The input sample
A
ABC
BC
A
The output sample:
2
3
My program to run on VS no errors, but submit said the result is wrong, what's the matter, a great god gives directions,
#include
#include
#include
using namespace std;
//calculate the program edit distance of
Int caldist (string str1, string str2)
{
Int dist=0;
Int len1 len2;
Len1=str1. Length ();
Len2=str2. Length ();
//calculate the biggest public subsequence
Vector
Vector
for(int i=0; I<=len2; I++)
{
Temp. Push_back (0);
}
for(int i=0; I<=len1; I++)
{
The map. The push_back (temp);
}
for(int i=0; I
For (int j=0; J
If (str1==str2 [j] [I])
{
Map [I + 1] [j + 1)=map [I] [j] + 1;
}
The else
{
Map [I + 1] [j + 1)=Max (map [j], [I + 1] map [I] [j + 1));
}
}
}
/*
for(int i=0; I<=len1; I++)
{
For (int j=0; J<=len2; J++)
{
Cout
Cout
Dist=map [len1] [len2];
//the length of the two strings and - the largest public subsequence * 2, which is the results
Dist=len1 + len2 - dist * 2;
Return dist.
}
Int main ()
{
Strings str1 str2;
Const int T=10;//T group enter
Int dist [T];
for(int i=0; I
Cin> Str1;
Cin> Str2;
Dist [I]=caldist (str1, str2);
}
Cout
Cout
return 0;
}