Skip to content

Instantly share code, notes, and snippets.

@VardanGrigoryan
Last active January 2, 2022 12:42
Show Gist options
  • Save VardanGrigoryan/8899883 to your computer and use it in GitHub Desktop.
Save VardanGrigoryan/8899883 to your computer and use it in GitHub Desktop.
Երկու տողերի միջև Լևենշտեյնի հեռավորության որոշում, Վագներ Ֆիշերի ալգորիթմի իրականացում C++ լեզվով
#include <vector>
double vagner_fisher_sed_algo(const std::string& s,
const std::string& d)
{
std::vector<std::vector<double> > t(s.length() + 1,
std::vector<double>(d.length() + 1));
t[0][0] = 0;
double o;
for (std::size_t j = 0; j != d.length(); ++j)
{
t[0][j + 1] = t[0][j] + 1;
}
for (std::size_t i = 0; i != s.length(); ++i)
{
t[i + 1][0] = t[i][0] + 1;
for (std::size_t j = 0; j != d.length(); ++j)
{
if(s[i] == d[j])
{
o = 0;
}
else
{
o = 1;
}
t[i + 1][j + 1] = std::min(std::min(t[i + 1][j] + 1,
t[i][j + 1] + 1), t[i][j] + o);
}
}
return t[s.length()][d.length()];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment